Jump to content

[SOLVED] "You have an error in your SQL syntax......"


chump1979

Recommended Posts

This is really bugging me now. Been trying to figure out the problem for hours and what hair i had left is now to torn out! hehe

 

All i want is this basic Insert code to work. I've done this many times before and it has worked fine. So not sure what is causing it to crap out. No doubt something obvious I am missing.

 

My code:

 


$conn = mysql_connect("$location","$username","$password");
mysql_select_db($database,$conn) or die ("Could not open database"); 
$sql = "INSERT INTO companies 

						(compname, 
						createdate, 
						createtime, 
						address1, 
						address2, 
						address3, 
						town, 
						county, 
						postcode, 
						landline, 
						mobile, 
						fax, 
						contactname, 
						email, 
						web, 
						tacking, 
						finishing, 
						insulating, 
						plastering, 
						supplier, 
						references, 
						traveldist, 
						contractor, 
						subcontractor, 
						camefrom, 
						desc, 
						emailkey) 

						 VALUES (

						'$_POST[compname]', 
						'$createdate', 
						'$createtime', 
						'$_POST[address1]', 
						'$_POST[address2]', 
						'$_POST[address3]', 
						'$_POST[town]', 
						'$_POST[county]', 
						'$_POST[postcode]', 
						'$_POST[landline]', 
						'$_POST[mobile]', 
						'$_POST[fax]', 
						'$_POST[contactname]', 
						'$_POST[email]', 
						'$_POST[web]', 
						'$_POST[tacking]', 
						'$_POST[finishing]', 
						'$_POST[insulating]', 
						'$_POST[plastering]', 
						'$_POST[supplier]', 
						'$_POST[references]', 
						'$_POST[traveldist]', 
						'$_POST[contractor]', 
						'$_POST[contractor]', 
						'$_POST[subcontractor]', 
						'$_POST[camefrom]', 
						'$_POST[desc]', 
						'$emailkey')";
$result2 = mysql_query($sql, $conn) or die(mysql_error());



 

The response:

 

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 'references, traveldist, contractor, subcontractor, ' at line 23

 

I'd appreciate any help.

 

Cheers

Marc

references is a reserved word -> http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html

 

Change it to something that's not a reserved word and the problem will go away.

 

Well, they'll go away if you change the fieldname desc as well to something that's also not a reserved word - descr maybe

Thanks for the reply. You were right. Not only references but also dist that i was using. Changed these two and all is working.

 

Saved me a lot more hassle.

 

I guess you miss these sort of mistakes when you're self taught. I didn't even know reserved words existed or were important!!

 

Thanks

Marc

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.