chump1979 Posted April 29, 2007 Share Posted April 29, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/49194-solved-you-have-an-error-in-your-sql-syntax/ Share on other sites More sharing options...
AndyB Posted April 29, 2007 Share Posted April 29, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/49194-solved-you-have-an-error-in-your-sql-syntax/#findComment-241056 Share on other sites More sharing options...
chump1979 Posted April 29, 2007 Author Share Posted April 29, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/49194-solved-you-have-an-error-in-your-sql-syntax/#findComment-241060 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.