kpetsche20 Posted September 30, 2008 Share Posted September 30, 2008 Hey, I keep getting this error for my insert query, it's driving me nuts because I can't find any problem. mysql_query("INSERT INTO order (userid) VALUES('".$userid."')") or die(mysql_error()); 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 'order (userid) VALUES('126')' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/126393-solved-simple-syntax-error/ Share on other sites More sharing options...
sKunKbad Posted September 30, 2008 Share Posted September 30, 2008 $sql ="INSERT INTO order (userid) VALUES ('" . $userid . "');" mysql_query($sql)OR die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/126393-solved-simple-syntax-error/#findComment-653613 Share on other sites More sharing options...
priti Posted September 30, 2008 Share Posted September 30, 2008 Hey, I keep getting this error for my insert query, it's driving me nuts because I can't find any problem. mysql_query("INSERT INTO order (userid) VALUES('".$userid."')") or die(mysql_error()); 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 'order (userid) VALUES('126')' at line 1 Is your userid datatype is varchar ... if not please remove '' i.e '123' instead it should be 123 if not numeric . Quote Link to comment https://forums.phpfreaks.com/topic/126393-solved-simple-syntax-error/#findComment-653615 Share on other sites More sharing options...
kpetsche20 Posted September 30, 2008 Author Share Posted September 30, 2008 It still give me the same error when I use the code you just sent. Quote Link to comment https://forums.phpfreaks.com/topic/126393-solved-simple-syntax-error/#findComment-653616 Share on other sites More sharing options...
kpetsche20 Posted September 30, 2008 Author Share Posted September 30, 2008 The database is setup fine, it's a mysql_query() error Hey, I keep getting this error for my insert query, it's driving me nuts because I can't find any problem. mysql_query("INSERT INTO order (userid) VALUES('".$userid."')") or die(mysql_error()); 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 'order (userid) VALUES('126')' at line 1 Is your userid datatype is varchar ... if not please remove '' i.e '123' instead it should be 123 if not numeric . Quote Link to comment https://forums.phpfreaks.com/topic/126393-solved-simple-syntax-error/#findComment-653619 Share on other sites More sharing options...
sKunKbad Posted September 30, 2008 Share Posted September 30, 2008 so, "order" is the name of your table? userid is a field? try running your sql directly on the database through phpmyadmin or mysql itself. Quote Link to comment https://forums.phpfreaks.com/topic/126393-solved-simple-syntax-error/#findComment-653620 Share on other sites More sharing options...
kpetsche20 Posted September 30, 2008 Author Share Posted September 30, 2008 I think that "order" cannot be the name of a table in a mysql database, when I changed the table name and it works now. Quote Link to comment https://forums.phpfreaks.com/topic/126393-solved-simple-syntax-error/#findComment-653621 Share on other sites More sharing options...
priti Posted September 30, 2008 Share Posted September 30, 2008 The database is setup fine, it's a mysql_query() error Hey, I keep getting this error for my insert query, it's driving me nuts because I can't find any problem. mysql_query("INSERT INTO order (userid) VALUES('".$userid."')") or die(mysql_error()); 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 'order (userid) VALUES('126')' at line 1 Is your userid datatype is varchar ... if not please remove '' i.e '123' instead it should be 123 if not numeric . I will also suggest you to run your query in PHPMyAdmin interface. what happen if you run following query in sql mode. INSERT INTO order (userid) VALUES(123); Quote Link to comment https://forums.phpfreaks.com/topic/126393-solved-simple-syntax-error/#findComment-653623 Share on other sites More sharing options...
redarrow Posted September 30, 2008 Share Posted September 30, 2008 just change the database setting from varchar to a int Quote Link to comment https://forums.phpfreaks.com/topic/126393-solved-simple-syntax-error/#findComment-653624 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.