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