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 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()); 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 . 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. 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 . 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. 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. 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); 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 Link to comment https://forums.phpfreaks.com/topic/126393-solved-simple-syntax-error/#findComment-653624 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.