我的插入声明有问题:
Create = function (LN,FN,Add,Tel,Cell)
LastName = tostring(LN);
FirstName = tostring(FN);
Address = tostring(Add);
Telephone =tostring(Tel);
Cellphone = tostring(Cell);
- 问题的根源
conn:execute([[INSERT INTO book(LastName, FirstName, Address, Telephone, Cellphone) VALUES ("]]"'"LastName"','"FirstName"','" Address"','" Telephone"','" Cellphone")]]'")
print ("\n Creating an account Successful")
end
答案 0 :(得分:3)
我建议你使用string.format
来放置数据:
Create = function (LN,FN,Add,Tel,Cell)
local LastName, FirstName, Address, Telephone, Cellphone = tostring(LN), tostring(FN), tostring(Add), =tostring(Tel), tostring(Cell)
local sQuery = [[INSERT INTO book(LastName, FirstName, Address, Telephone, Cellphone) VALUES ('%s', '%s', '%s', '%s', '%s')]]
conn:execute( sQuery:format(LastName, FirstName, Address, Telephone, Cellphone) )