Hi all
I'm trying to INSERT INTO a table, and am getting this stupid error.
[CODE]no such column: value1[/CODE]
Where value1 is the contents of the value I'm trying to save
Why is SQL using my values to refer to the column names?
I have tried with quotes around different parts, used ' and ` all with no effect other than changing which value it gives me an error about not being a valid column
I've tried using
[CODE]query = "INSERT INTO table (column1, column2, column3, column4) VALUES ('" .. value1 .. "', '" .. value2 .. "', '" .. value3 .. "', '" .. value4 .. "')"[/CODE]
again with and without various types of quotes around the column/value names...
Here is my current code:
[CODE]
--save the post
query = "INSERT INTO table VALUES ('" .. value1 .. "', '" .. value2 .. "', '" .. value3 .. "', '" .. value4 .. "')"
result = sql.Query(query)
if (result) then
print("Stuff saved!")
else
print("Stuff not saved :(")
print(sql.LastError())
end
[/CODE]
Please help I'm at my wits end figuring this one out
You are doing "if ( result )" which will only return true if it returned any data. You see, if the query fails it returns [I]false[/I], if there is no data retrieved (such as when you are inserting or updating data) it will return [I]nil[/I]. Simply change your line to "if ( result == false )" then it should work.
[editline]8th August 2013[/editline]
However, I suspect that your query might fail if you are inserting data on an existing row (do you have a primary key?).
Please, [i]please[/i] run your input through sql.SQLStr first. :tinfoil:
The "no such column" error you're getting may in fact be an old error that isn't applicable to the current query, but is being displayed because your code is incorrectly interpreting a successful query as a failed query.
[QUOTE=Luni;41762810]The "no such column" error you're getting may in fact be an old error that isn't applicable to the current query, but is being displayed because your code is incorrectly interpreting a successful query as a failed query.[/QUOTE]
So basically exactly what I told him 13 hours ago.
INSERT shouldn't return anything either, you're not querying for data to be returned; you're inserting...
Make sure the rows are being inserted, if they are disregard the error and check how you do your checks..
[QUOTE=Acecool;41764136]INSERT shouldn't return anything either, you're not querying for data to be returned; you're inserting...
Make sure the rows are being inserted, if they are disregard the error and check how you do your checks..[/QUOTE]
So basically also exactly what I told him 13 hours ago.
Sorry, you need to Log In to post a reply to this thread.