lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Give a try at this one, this should work, I noticed that you 
had the form tag not closed properly maybe that was your problem.

--- // code  START //
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
<head>
       <title>CGILua Test Updating SQLite3</title>
</head>
<body>
<h2>Form Handling</h2>
<p>Entering values on this form should display them as values in the first
submission</p>
<form method="post">
       <label>User name : </label><input name="name" maxlength="20" size="20">
       <label>Age : </label><input name="age" maxlength="3" size="3">
       <input type="submit" value="Post it">
</form>
<p>The values should show the previous POST</p>
<p>Values: Username = <%= cgilua.POST.name or "(not set)"%>, Age =
<%=cgilua.POST.age or "(not set)"%></p>

<%
require("luasql.sqlite3")
local env = (luasql.sqlite3())

conn = env:connect("luasql-test")
query = [[
CREATE TABLE IF NOT EXISTS people (
       id INTEGER PRIMARY KEY ASC,
       name VARCHAR NOT NULL,
       age INTEGER NOT NULL
)
]]

conn:execute(query);
nm = cgilua.POST.name
ag = cgilua.POST.age
assert( conn:execute([[
INSERT INTO people(name, age) VALUES('" ..nm .."', '"
..ag.."')
]]))
%>

<h2>Date</h2>

<p>Today is: <%= os.date() %></p>

<table>
<tr><th>Name</th><th>Age</th></tr>
<%
cur = assert( conn:execute("SELECT * FROM people") )
row = cur:fetch({},"a")
while row do
       %><tr>
    <td><% print(row.name) %></td>
    <td><% print(row.age) %></td>
</tr> <%
       row = cur:fetch(row, "a")
end

cur:close(); conn:close(); env:close();
%>

</table>
</body>
</html>
--- // code  END //