0
$result1 = mysql_query("Select * from tbl_lastLocation where driver_id='$user_id');
if(mysql_num_rows($result1)){
    $result2 = mysql_query("UPDATE tbl_lastLocation SET Latitude='$Latitude',Longtitude='$Longitude',vehicle_id='$vehicle_id',data_create='$date_create',time_create='$time_create' WHERE driver_id='$user_id'"); //line 17
}
else{
    $result2 = mysql_query("INSERT INTO tbl_lastLocation (driver_id,vehicle_id,Latitude,Longtitude,data_create,time_create) VALUES ('$user_id','$vehicle_id','$Latitude','$Longitude','$date_create','$time_create')");
}

$data["result"] = "1";

    echo json_encode($data);

?>

I am getting an error:

PHP Parse error:  syntax error, unexpected 'UPDATE' (T_STRING) in /home/barbodpl/public_html/its_api/lastlocation.php on line 17

What does the error mean and how do I fix it?

  • 3
    missing " at the end of first SQL – Keyur Padalia Aug 24 '17 at 12:25
  • **The `mysql` PHP extension is dead** -- Stop using the [`mysql` PHP extension](http://php.net/manual/en/function.mysql-connect.php). It is old, deprecated since PHP 5.5 and completely removed in PHP 7.0. Use [`mysqli`](http://php.net/manual/en/book.mysqli.php) or [`PDO_mysql`](http://php.net/manual/en/ref.pdo-mysql.php) instead. Read the answers to [this question](https://stackoverflow.com/q/12859942/4265352) to learn more about why and how. – axiac Aug 24 '17 at 12:30

1 Answers1

1
 $result1 = mysql_query("Select * from tbl_lastLocation where driver_id='$user_id');

This is missing the closing " therefore it should be:

$result1 = mysql_query("Select * from tbl_lastLocation where driver_id='$user_id'");       

Mysql functions are deprecated, please use MySQLi and prepared statements because your query looks vulnerable to injection.

IsThisJavascript
  • 1,726
  • 2
  • 16
  • 25