0

my code have an error in update part, it shows for me this 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 '( reqdate= '2012-12-17',lat1= '26.18355762868919',long1= '50.30387832641602',lat' at line 1

and this is my code about update:

if(mysql_fetch_array($query1))
{
$datex = strtotime(date('Y-m-d H:i:s'))+36000;
$time = date('H:i:s', $datex);
$date=date('Y-m-d', $datex);
$result=mysql_query("SELECT * FROM sensorusers  WHERE uid='$uid'");

mysql_query("UPDATE requests SET ( reqdate= '$date',lat1= '$lat1',long1= '$lng1',lat2= '$lat2',long2='$lng2',lat3='$lat3',long3='$lng3',lat4='$lat4',long4='$lng4',inout='$type',time='$time') WHERE  sid= '$drivers'") or die(mysql_error());

$Alpha  = @mysql_query($query2,$db); //Execute Query

}
0

2 Answers 2

0

just remove the parenthesis and surely it will execute, eg

UPDATE requests 
SET   reqdate = '$date',
      lat1    = '$lat1',
      long1   = '$lng1',
      lat2    ='$lat2', 
      long2   = '$lng2', 
      lat3    = '$lat3',
      long3   = '$lng3',
      lat4    = '$lat4',
      long4   = '$lng4',
      `inout` = '$type',    // << RESERVED KEYWORD
      time    = '$time' 
WHERE  sid    = '$drivers'

INOUT is a RESERVED KEYWORD. You should escape it using backtick.

be warned that this code is vulnerable with SQL Injection, please read the article below to learn how to prevent from it,

11
  • i removed ( ) but it stills give me the same error Dec 16, 2012 at 21:56
  • what is the exact error message?
    – John Woo
    Dec 16, 2012 at 21:57
  • this 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 'inout='In',time='10:59:02') WHERE sid= '20080699-bedoor'' at line 1 Dec 16, 2012 at 21:59
  • that is now the new error. not the same with the previous error. INOUTis a reserved keyword,you should escape it. see my updated answer.
    – John Woo
    Dec 16, 2012 at 22:01
  • hmm , i used the same name 'inout' in another query where i was inserted the data not update the data and it works fine Dec 16, 2012 at 22:04
0

Syntax Error

Remove the ( and ) in your SQL.

mysql_query("UPDATE requests SET `reqdate` = '$date',lat1= '$lat1',long1= '$lng1',lat2= '$lat2',long2='$lng2',lat3='$lat3',long3='$lng3',lat4='$lat4',long4='$lng4',inout='$type',time='$time' WHERE  sid= '$drivers'") or die(mysql_error());

Also, consider using PDO or mysqli_* functions instead of mysql_* functions.

4
  • i tried to remove them ,the same error showed for me :( .. how i can use the function that u determined? Dec 16, 2012 at 21:57
  • BTW, you need to escape the column names using a backslash (`). Because, a few names seems to be reserved names. Dec 16, 2012 at 22:04
  • Do u mean to put `` for each column? Dec 16, 2012 at 22:08
  • Yeah! I meant that. :) At least for the inout field... Dec 16, 2012 at 22:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.