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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.