SirChick Posted November 11, 2007 Share Posted November 11, 2007 I have a query in my php file but i keep getting a syntax error but not sure what the syntax is precisely... this is what i got: $query = mysql_query("INSERT INTO `hospital` (HospitalID,CountryID,UserID,Time,When,IllnessType) Values ('1','1','$ID','7200','$Date','Autumn Flu')") or die(mysql_error()); And i get: 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 'When,IllnessType) Values ('1','1','72','7200','2007-11-11 23:19:59','Autum' at line 1 Just to add Time = Integer and When =date("Y-m-d H:i:s",time()); format just so you know encase you might have thought it was my time input. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 11, 2007 Share Posted November 11, 2007 It might be because one of your field names is "Time". Do this $query = mysql_query("INSERT INTO `hospital` (HospitalID,CountryID,UserID,`Time`,When,IllnessType) Values ('1','1','$ID','7200','$Date','Autumn Flu')") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 11, 2007 Share Posted November 11, 2007 i think when is also reserve word in sql put a (` ) around it Quote Link to comment Share on other sites More sharing options...
SirChick Posted November 11, 2007 Author Share Posted November 11, 2007 thanks guys you are both correct When and Time are reserved words. thankyou Quote Link to comment Share on other sites More sharing options...
AndyB Posted November 11, 2007 Share Posted November 11, 2007 i think when is also reserve word in sql put a (` ) around it Indeed, when is a reserved word. The better solution is to avoid the backticks and use variable names that are not reserved words. http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html Quote Link to comment 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.