user3548071
user3548071

Reputation: 1

Lua insert statement

I'm having problems with my insert statement:

Create = function (LN,FN,Add,Tel,Cell)
    LastName = tostring(LN);
    FirstName = tostring(FN);
    Address = tostring(Add);
    Telephone =tostring(Tel); 
    Cellphone = tostring(Cell);

--source of the problem

conn:execute([[INSERT INTO book(LastName, FirstName, Address, Telephone, Cellphone) VALUES ("]]"'"LastName"','"FirstName"','" Address"','" Telephone"','" Cellphone")]]'")

 print ("\n Creating an account Successful")
 end 

Upvotes: 0

Views: 1102

Answers (1)

hjpotter92
hjpotter92

Reputation: 80639

I'd suggest that you use the string.format for placing the data:

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) )

Upvotes: 3

Related Questions