Welcome to WebmasterWorld Guest from 54.167.83.224

Forum Moderators: open

Message Too Old, No Replies

mysql syntax error

     
6:45 am on Sep 16, 2012 (gmt 0)

New User

joined:Sept 15, 2012
posts: 2
votes: 0


This is my query

$query = "INSERT INTO requirement (desc) VALUES ('test1') ";

i am getting below given 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 'desc) VALUES ('test1')' at line 1
11:34 am on Sept 16, 2012 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10544
votes: 8


welcome to WebmasterWorld, vaayaaedu!

i think using VALUES (plural) requires a comma-separated list of values.
12:00 pm on Sept 16, 2012 (gmt 0)

Moderator from GB 

WebmasterWorld Administrator brotherhood_of_lan is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Jan 30, 2002
posts:4842
votes: 1


Welcomes to the forums

desc is a reserved word [dev.mysql.com] in MySQL, so that will throw an error.

You can still use it but should enclose it in backticks. It's generally considered good practice to avoid naming columns as reserved words, or get in the habit of using backticks for all column names.

So this should work:
$query = "INSERT INTO requirement (`desc`) VALUES ('test1') ";
12:03 pm on Sept 16, 2012 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10544
votes: 8


desc is a reserved word

oops - i didn't even "see" that!
9:35 pm on Sept 16, 2012 (gmt 0)

Moderator from GB 

WebmasterWorld Administrator brotherhood_of_lan is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Jan 30, 2002
posts:4842
votes: 1


Yep it's something that people rarely encounter imo, it's not like it's worth memorising the list.

This one has me going for a while, but should have been obvious

SELECT * FROM acc_soc AS as INNER JOIN ......