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

}
John Woo
  • 258,903
  • 69
  • 498
  • 492
Sara Sayyar
  • 23
  • 1
  • 7

2 Answers2

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,

Community
  • 1
  • 1
John Woo
  • 258,903
  • 69
  • 498
  • 492
  • i removed ( ) but it stills give me the same error – Sara Sayyar Dec 16 '12 at 21:56
  • what is the exact error message? – John Woo Dec 16 '12 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 – Sara Sayyar Dec 16 '12 at 21:59
  • that is now the new error. not the same with the previous error. `INOUT`is a [reserved keyword](http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html),you should escape it. see my updated answer. – John Woo Dec 16 '12 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 – Sara Sayyar Dec 16 '12 at 22:04
  • yes, but maybe you have escaped it using backtick. – John Woo Dec 16 '12 at 22:06
  • i changed to inout1.. it gives me the same errrrrrror :( i will cry now – Sara Sayyar Dec 16 '12 at 22:12
  • what error are you getting now? always post the error message please. – John Woo Dec 16 '12 at 22:12
  • 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 ') WHERE sid= '20080699-bedoor'' at line 1 – Sara Sayyar Dec 16 '12 at 22:15
  • remove the closing parenthesis, can you show the query you are executing? – John Woo Dec 16 '12 at 22:17
  • waaw its worked! i forgot to remove the closed ) .. itttttsss worked!!! thank u very much! and i added also `` for each column – Sara Sayyar Dec 16 '12 at 22:21
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.

Community
  • 1
  • 1
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252