homepage Welcome to WebmasterWorld Guest from 54.145.211.125
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

    
mysql syntax error
vaayaaedu



 
Msg#: 4495917 posted 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

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



 
Msg#: 4495917 posted 11:34 am on Sep 16, 2012 (gmt 0)

welcome to WebmasterWorld, vaayaaedu!

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

brotherhood of LAN

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



 
Msg#: 4495917 posted 12:00 pm on Sep 16, 2012 (gmt 0)

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

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



 
Msg#: 4495917 posted 12:03 pm on Sep 16, 2012 (gmt 0)

desc is a reserved word

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

brotherhood of LAN

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



 
Msg#: 4495917 posted 9:35 pm on Sep 16, 2012 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved