2015-06-22 110 views
1

目前我在運行我的代碼時遇到問題,即使我可以在本地主機上運行它。在web主機上運行我的代碼時遇到困難

if($con->connect_error){ 
    $response['success'] =0; 
    $response['message'] ='could not connect to database'; 
    print(json_encode($response)); 
    die(print(json_encode($response))); 
} 

$response['success'] =1; 
$response['message'] ='successfully connected to the database'; 
print(json_encode($response)); 


$depart = $_GET['depart']; 
$destination = $_GET['destination']; 
$sql = "INSERT INTO request (dateNtime, depart, destination, status) VALUES (now(),$depart,$destination,0)"; 
$mysql=mysqli_query($con,$sql); 

if($mysql) 
{ 
    echo "successfully"; 
} 
else 
{ 
    echo mysqli_error($con); 
} 

mysqli_close($con); 

目前,這是我得到的直播服務器運行該代碼的錯誤:

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 '\'users\',0)' at line 1 

我想知道這是什麼錯誤的原因是什麼?

+0

**危險**:您很容易[SQL注入攻擊](http://bobby-tables.com/)**,您需要[防禦](http://stackoverflow.com/問題/ 60174/best-way-to-prevent-sql -injection-in-php)自己從。 – Quentin

回答

1

從php文檔和你的錯誤,似乎mysqli_error()請求連接作爲參數,將其更改爲mysqli_error($con)它應該工作,從那裏你可以看到是什麼導致它錯誤。

+0

感謝您的評論。正如你所說,我編輯了我的問題。現在,我收到了上述不同的錯誤。爲什麼這個錯誤的意思?它與MySQL版本問題有關嗎? –

+1

@ DH​​P_07 - 您現在有一個不同的問題。你應該接受這個答案並提出一個新問題,而不是改變問題,所以這個答案不再有任何意義。 – Quentin

0

在創建查詢之後,請執行echo $sql;然後使用所獲得的內容更新問題。 大概你會看到你的$destination是錯的,但我不能確定,因爲我不知道你的桌子是什麼樣的。如果你在mysql中運行該函數,也請包含DESC request的結果。