RSprinkel Posted September 17, 2006 Share Posted September 17, 2006 Hi all,I am getting this error when I try to enter data into a database via a form.Here is the error: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 'mod, track) VALUES('PA_LowRider'','09/14/2006','Cup','Cup','Richmond')' at line 1Here is the code trying to process the data into the database.[code]<?phpinclude 'db.php';$sierra = $_POST['sierra'];$date = $_POST['date'];$series = $_POST['series'];$mod = $_POST['mod'];$track = $_POST['track'];$sierra = stripslashes($sierra);$date = stripslashes($date);$series = stripslashes($series);$mod = stripslashes($mod);$track = stripslashes($track); //insert info into win table$sql = mysql_query ("INSERT INTO win (sierra, date, series, mod, track)VALUES('$sierra','$date','$series','$mod','$track')") or die (mysql_error());if(!$sql){ echo 'There has been an error processing this win. Please contact the webmaster.';}mysql_close($connection);//show user decision pageinclude 'win_filed.php';?>[/code] Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 17, 2006 Share Posted September 17, 2006 Avoid using [b]reserved words[/b] as table names or field names. Here's a list of what not to use:http://dev.mysql.com/doc/refman/5.0/en/reserved-words.htmlThe best solution would be to rename 'mod' to 'xmod' or something. The sloppy workaround is to use backticks on reserved words like `mod`While debugging, it never hurts to echo the query as well as the error, thus:[code]$query = " ... whatever it is ...";$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);// gotcha![/code] Quote Link to comment Share on other sites More sharing options...
RSprinkel Posted September 17, 2006 Author Share Posted September 17, 2006 Thanks for the info. Quote Link to comment Share on other sites More sharing options...
Guardian2006 Posted September 18, 2006 Share Posted September 18, 2006 Your error message also indicates you have to single quotes together -[quote]'PA_LowRider'',[/quote] Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 18, 2006 Share Posted September 18, 2006 [quote author=Guardian2006 link=topic=108398.msg436531#msg436531 date=1158589460]Your error message also indicates you have to single quotes together -[quote]'PA_LowRider'',[/quote][/quote]There's an interesting observation. I suspect the first of those trailing single quotes actually came with the posted information and was originally escaped (and would have gone into the database OK) but the stripslashes removed the escaping and rendered it back as ' which caused the mistake. Skip stripslashes. Quote Link to comment Share on other sites More sharing options...
RSprinkel Posted September 18, 2006 Author Share Posted September 18, 2006 Thanks for all the help guys. I got all those little nasty bugs worked out. Now I am gonna try to do some sorting or something and hope I don't mess this all up after all of this, LOL.Again Thanks for the Help and I am sure I will have some more questions regarding some other help on soon. Quote Link to comment 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.