Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I keep getting the following SQL syntax error:

ERROR MESSAGE

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, tag ) VALUES( '1', '1', '1', 'Jakis pis', 'Jakis tag')' at line 1Query failed

MYSQL QUERY:

$qry = "INSERT INTO lang".$lang." ( lang, submenu, live, desc, tag ) VALUES( '$lang', '$submenu', '$live', '$desc', '$tag') ";

print_r($qry);

Full SQL Query: INSERT INTO lang1 ( lang, submenu, live, desc, tag ) VALUES( '1', '1', '1', 'Some desc', 'Some tags')

I checked the table names and column names multiple times, can you see any syntax error?

share|improve this question
    
WARNING you code might be suseptible to sql injection attacks. –  Daniel A. White Jan 30 '12 at 13:57
2  
Can you post the error message? –  Lamak Jan 30 '12 at 13:58
    
@daniel - please note this will be for my localhost only. Also I'm using mysql_real_escape_string –  User789 Jan 30 '12 at 13:59
    
Are any of 'lang', 'submenu' or 'live' columns which only accept ints? –  dougajmcdonald Jan 30 '12 at 13:59
1  
@NewUser A tip: About 95% of the time, the exact place where MySQL places the first ' of the error message is where to begin looking for problems. Though it's understandable if you weren't aware of the reserved keywords. –  Michael Berkowski Jan 30 '12 at 14:03
show 2 more comments

2 Answers

up vote 10 down vote accepted

try:

  ( `lang`, `submenu`, `live`, `desc`, `tag` )

since desc is a MySQL reserved word

share|improve this answer
    
+1 for spotting it before the error message was posted. –  Michael Berkowski Jan 30 '12 at 14:02
    
My MySQL did not point out what was the issue exactly? My error settings are on E_All –  User789 Jan 30 '12 at 14:10
add comment

Try to insert your query,

INSERT INTO lang1 ( lang, submenu, live, desc, tag ) VALUES( '1', '1', '1', 'Some desc', 'Some tags')

in phpMyAdmin directly and see what it says their...

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.