Woodburn2006 Posted November 21, 2007 Share Posted November 21, 2007 i get this error everytime i do a bit of code: 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 'group, group_position) VALUES (Gosport,2007-11-21,Roger Calton,1,eg - 32:875,13,' at line 1 the code that is executing is: $driver = $_POST['driver']; $groupnumber = $_POST['groupnumber']; $grouppos = $_POST['grouppos']; $lap = $_POST['lap']; $position = $_POST['position']; foreach($driver as $a){ $b = current($groupnumber); $c = current($grouppos); $d = current($lap); $e = current($position); $track = $_POST['track']; $date = date('Y-m-d', $_POST['date']); $query = mysql_query("INSERT INTO results (track, date, driver, race_position, time, group, group_position) VALUES ($track,$date,$a,$e,$d,$c,$b)") or die(mysql_error()); mysql_query($query, $connection); next ($groupnumber); next ($grouppos); next ($lap); next ($position); } any ideas to why this is happening? Quote Link to comment https://forums.phpfreaks.com/topic/78236-solved-dont-understand-this-error/ Share on other sites More sharing options...
trq Posted November 21, 2007 Share Posted November 21, 2007 This line.... $query = mysql_query("INSERT INTO results (track, date, driver, race_position, time, group, group_position) VALUES ($track,$date,$a,$e,$d,$c,$b)") or die(mysql_error()); Should be.... $query = "INSERT INTO results (track, date, driver, race_position, time, group, group_position) VALUES ('$track','$date','$a','$e','$d','$c','$b')"; And, this line.... mysql_query($query, $connection); should be.... mysql_query($query, $connection) || die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/78236-solved-dont-understand-this-error/#findComment-395907 Share on other sites More sharing options...
Woodburn2006 Posted November 21, 2007 Author Share Posted November 21, 2007 i made the changes you told me to do but i still get this error still: 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 'group, group_position) VALUES ('Gosport','2007-11-21','Roger Calton','1','eg - 3' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/78236-solved-dont-understand-this-error/#findComment-395917 Share on other sites More sharing options...
akitchin Posted November 21, 2007 Share Posted November 21, 2007 my guess is that it's because "time" is a reserved word in MySQL. try changing that column name, adjusting the query appropriately, and running again. Quote Link to comment https://forums.phpfreaks.com/topic/78236-solved-dont-understand-this-error/#findComment-395920 Share on other sites More sharing options...
Woodburn2006 Posted November 21, 2007 Author Share Posted November 21, 2007 nope, still no joy. i dont understand what is going wrong, i use the same syntax in many other pages but they all work fine Quote Link to comment https://forums.phpfreaks.com/topic/78236-solved-dont-understand-this-error/#findComment-395929 Share on other sites More sharing options...
trq Posted November 21, 2007 Share Posted November 21, 2007 Ok, prior to executing your query use.... die($query); so we can see exactly what the query looks like. Quote Link to comment https://forums.phpfreaks.com/topic/78236-solved-dont-understand-this-error/#findComment-395932 Share on other sites More sharing options...
Woodburn2006 Posted November 21, 2007 Author Share Posted November 21, 2007 ok cool, the query is like this INSERT INTO results (track, date, driver, race_position, fastest_lap, group, group_position) VALUES ('Gosport','2007-11-21','Roger Calton','1','32:87589','13','5') Quote Link to comment https://forums.phpfreaks.com/topic/78236-solved-dont-understand-this-error/#findComment-395937 Share on other sites More sharing options...
PFMaBiSmAd Posted November 21, 2007 Share Posted November 21, 2007 syntax to use near 'group The portion of the query right after single-quote in the error that mysql outputs is the point where it found something it cannot figure out. GROUP is a reserved keyword. [From the previous post - time is a data type, not a reserved keyword and it is permitted to be used as a column name.] Quote Link to comment https://forums.phpfreaks.com/topic/78236-solved-dont-understand-this-error/#findComment-395944 Share on other sites More sharing options...
Woodburn2006 Posted November 21, 2007 Author Share Posted November 21, 2007 quality, works fine now thanks Quote Link to comment https://forums.phpfreaks.com/topic/78236-solved-dont-understand-this-error/#findComment-395966 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.