DeathDisease Posted March 7, 2007 Share Posted March 7, 2007 Hello all, I ran into a little problem with my php script, mysql is returning this error: Error Occured: 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 'set (aimxfov, aimyfov, aimxvec, aimyvec, aimzvec) VALUES ('72','865','936','908'' at line 1 This is my code: <?php include("db.php"); $xfov = $_POST['xfov']; $yfov = $_POST['yfov']; $xvec = $_POST['xvec']; $yvec = $_POST['yvec']; $zvec = $_POST['zvec']; if($_POST['submit']){ $query = mysql_query("INSERT INTO set (aimxfov, aimyfov, aimxvec, aimyvec, aimzvec) VALUES ('$xfov','$yfov','$xvec','$yvec','$zvec')") or die("Error Occured: ".mysql_error()); } if(!$query){ echo "Error adding entry."; }else{ echo "Entry added successfully."; } include("dbclose.php"); ?> I've noticed that in the error on this line ('72','865','936','908'' that it is missing the closing bracket, I donno if thats the problem or not but in my code the bracket is their. Any suggestions? Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/41682-mysql-syntax-error/ Share on other sites More sharing options...
effigy Posted March 7, 2007 Share Posted March 7, 2007 set is a reserved word; try `set`. Also, this... $xfov = $_POST['xfov']; $yfov = $_POST['yfov']; $xvec = $_POST['xvec']; $yvec = $_POST['yvec']; $zvec = $_POST['zvec']; ...can be reduced with extract, but you may want to use a foreach loop instead, in order to pass each value through mysql_real_escape_string to protect yourself against SQL injections and syntax errors. Link to comment https://forums.phpfreaks.com/topic/41682-mysql-syntax-error/#findComment-201997 Share on other sites More sharing options...
DeathDisease Posted March 7, 2007 Author Share Posted March 7, 2007 Thanks for the help effigy worked perfect. I donno what i'd do without ya's . Link to comment https://forums.phpfreaks.com/topic/41682-mysql-syntax-error/#findComment-202007 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.