Jump to content

MYSQL Syntax Error


DeathDisease

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

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