shotos Posted November 21, 2008 Share Posted November 21, 2008 hi i got this mysql query $input = "INSERT INTO category(name, By) VALUES('$category','$_SESSION[user]')"; $write = mysql_query($input,$db->link) or die(mysql_error() . " Query was: $input"); which generates this 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 'By) VALUES('Grain','kwasi')' at line 1 Query was: INSERT INTO category(name, By) VALUES('Grain','kwasi') problem is i dun see de error... thanks in advance Link to comment https://forums.phpfreaks.com/topic/133636-solved-mysql-error/ Share on other sites More sharing options...
mtoynbee Posted November 21, 2008 Share Posted November 21, 2008 Try this instead: $input = "INSERT INTO category([name], [by]) VALUES('$category','$_SESSION[user]')"; $write = mysql_query($input,$db->link) or die(mysql_error() . " Query was: $input"); "BY" is a reserved word therefore is needs square brackets for MySQL to treat it as a column name. Link to comment https://forums.phpfreaks.com/topic/133636-solved-mysql-error/#findComment-695257 Share on other sites More sharing options...
JasonLewis Posted November 21, 2008 Share Posted November 21, 2008 It's better to not name columns as a reserved word, IMO. For future reference, a list of reserved words can be found here. Link to comment https://forums.phpfreaks.com/topic/133636-solved-mysql-error/#findComment-695259 Share on other sites More sharing options...
shotos Posted November 21, 2008 Author Share Posted November 21, 2008 thnks i replaced 'By' with sumtin else. Link to comment https://forums.phpfreaks.com/topic/133636-solved-mysql-error/#findComment-695262 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.