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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Monopoly
Forum Commoner
Posts: 41
Joined: Wed May 21, 2008 1:19 pm

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

Post 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
Monopoly
Forum Commoner
Posts: 41
Joined: Wed May 21, 2008 1:19 pm

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

Post 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.
Reviresco
Forum Contributor
Posts: 172
Joined: Tue Feb 19, 2008 4:18 pm
Location: Milwaukee

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

Post 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.
Monopoly
Forum Commoner
Posts: 41
Joined: Wed May 21, 2008 1:19 pm

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

Post 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
nathan_nateben
Forum Newbie
Posts: 4
Joined: Wed Apr 29, 2009 4:57 pm

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

Post 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
Monopoly
Forum Commoner
Posts: 41
Joined: Wed May 21, 2008 1:19 pm

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

Post by Monopoly »

They match :(
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

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

Post 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
Post Reply