0

我的插入语句有问题:

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 
4

1 回答 1

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) )
于 2014-04-18T09:58:06.903 回答