Page 1 of 1

You have an error in your SQL syntax; check the ...

Posted: Wed Apr 29, 2009 10:38 am
by Monopoly
I bow before you. The further pieces of code worked well up till now:

Code: Select all

 
$sql="INSERT INTO forum_question (forums_id, id, topic, detail, name, datetime, last_reply, user_ip, lock ) VALUES ('$f_id', '$id', '$topic', '$detail', '$name', '$time', '$time', '$ip', '$no' )";
$result=mysql_query($sql) or die(mysql_error());
 
But some moments ago I began getting a strange error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'lock ) VALUES ('12', '2', 'test', 'test', 'test', '1241015213', '1241015213', '9' at line 1


Please note that other queries run absolutely well, even equivalent INSERT INTO in other scripts, located on the same server, in the same folder, sending commands to the tables in the same database run without any errors as well.

I thank you in advance

Re: You have an error in your SQL syntax; check the ...

Posted: Wed Apr 29, 2009 11:43 am
by Monopoly
I googled this issue and didn't find anything good but some topics where people refer it to the fact that the host admins migrated to MySql version 4.1.x.x or something like that.

Re: You have an error in your SQL syntax; check the ...

Posted: Wed Apr 29, 2009 11:48 am
by Reviresco
I would check the value being inserted for the lock field -- there may be a character like an apostrophe, quotation mark, semi-colon, etc., that's causing the query to choke.

Re: You have an error in your SQL syntax; check the ...

Posted: Wed Apr 29, 2009 12:04 pm
by Monopoly
Reviresco wrote:I would check the value being inserted for the lock field -- there may be a character like an apostrophe, quotation mark, semi-colon, etc., that's causing the query to choke.
The problem is not that. BTW, a found that newer scripts (that have been uploaded after the DB update) also have that problem.

Ohhh man, I'll screw up whether I don't get any solution

Re: You have an error in your SQL syntax; check the ...

Posted: Wed Apr 29, 2009 5:26 pm
by nathan_nateben
Try printing out the query with your error message. Compare the query values received to the database data types. Might help. I posted an example of doing this in: viewtopic.php?f=1&t=99387

Re: You have an error in your SQL syntax; check the ...

Posted: Thu Apr 30, 2009 2:25 pm
by Monopoly
They match :(

Re: You have an error in your SQL syntax; check the ...

Posted: Thu Apr 30, 2009 2:30 pm
by Eran
LOCK is a MySQL reserved word. You need to escape it with backticks (ie, `lock`) to use it in a query. Preferably you shouldn't use reserved words for your metadata (table and column names).

http://dev.mysql.com/doc/refman/5.1/en/ ... words.html