Welcome to WebmasterWorld Guest from 54.226.27.104

Forum Moderators: open

Message Too Old, No Replies

mysql syntax error

     

vaayaaedu

6:45 am on Sep 16, 2012 (gmt 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

phranque

11:34 am on Sep 16, 2012 (gmt 0)

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



welcome to WebmasterWorld, vaayaaedu!

i think using VALUES (plural) requires a comma-separated list of values.

brotherhood of LAN

12:00 pm on Sep 16, 2012 (gmt 0)

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



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') ";

phranque

12:03 pm on Sep 16, 2012 (gmt 0)

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



desc is a reserved word

oops - i didn't even "see" that!

brotherhood of LAN

9:35 pm on Sep 16, 2012 (gmt 0)

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



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

Featured Threads

Hot Threads This Week

Hot Threads This Month