Jump to content

[SOLVED] Query Syntax issue


SirChick

Recommended Posts

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

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());

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.