2017-08-24 93 views
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); 

>PHP解析錯誤:語法錯誤,意想不到的 '更新'(T_STRING)

我得到一個錯誤:

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

什麼是錯誤的意思是,我如何修復它?

+3

失蹤」在第一SQL –

+0

**的'mysql' PHP擴展的末端是死** - 停止使用['mysql' PHP擴展](http://php.net/manual/en/function.mysql-connect.php )。這是舊的,從PHP 5.5開始不推薦使用,並且在PHP 7.0中完全刪除。使用['mysqli'](http://php.net/manual/en/book.mysqli.php)或['PDO_mysql'](http://php.net/manual/en/ref.pdo-mysql。而不是。閱讀[這個問題]的答案(https://stackoverflow.com/q/12859942/4265352)以瞭解更多關於爲什麼和如何。 – axiac

回答

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

這缺少結束「因此它應該是:

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

MySQL的函數已被棄用,請使用庫MySQLi和預準備的語句,因爲您的查詢似乎容易受到注射

+0

是的,它的工作,謝謝 –

相關問題