2013-10-03 38 views
0

我想在MySQL數據庫中刪除記錄時,我需要選擇與WHERE子句中兩個同時列刪除一個MySQL記錄:使用多個選擇

$result3 = mysqli_query($con, " DELETE FROM Waiting WHERE ToUser='$ToEmail' AND ImageID='$ToEmailDB' "); 
    if ($result3==false) { 
     echo "No images waiting for " . $ToEmail . " for image " . $ToEmailDB; 
    } 
    else { 
     echo "Image and record deleted for " . $ToEmail . " for image " . $ToFileName . ".jpg and record " .     $GuessImageID; 
    } 

當我執行該語句$result3 returns true但進入不會被刪除。我需要在格式中更改什麼?字符串回顯表中輸入的正確數據。

+1

難道你嘗試顯示查詢a nd通過一些數據庫客戶端手動運行它?你有什麼迴應? – Moby04

+0

在我的測試中,我使用Android Studio調試器來檢查回聲,並使用簡單的html接口與服務器腳本進行初始調試。我在服務器上使用MyPHPAdmin來檢查數據庫內容並監視更改。作爲一個方面說明,Eclipse在調試過程中不斷崩潰,所以我切換到了Android Studio。到目前爲止,Android Studio更穩定,更容易調試。 – user2431174

回答

0

如果您的查詢執行成功,則始終返回TRUE。只有在查詢失敗則返回FALSE由於每PHPdocumentation

mysqli_query() Returns FALSE on failure. For successful SELECT, SHOW, 
DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. 
For other successful queries mysqli_query() will return TRUE. 

從Moby04的評論

如果您要檢查有什麼東西在實際刪除使用mysqli_affected_rows()功能。

+1

沒錯,如果你想檢查是否真的被刪除了,請使用mysqli_affected_rows函數(http://php.net/manual/en/mysqli.affected-rows.php) – Moby04

0

如果SQL查詢成功執行,即使DELETE未刪除數據庫中的任何行,查詢也將返回true。

http://php.net/manual/en/mysqli.affected-rows.php

要回答你的問題,你需要找到的行數影響

$result3 = mysqli_query($con, " DELETE FROM Waiting WHERE ToUser='$ToEmail' AND ImageID='$ToEmailDB' "); 

if (!$result3) { 
    echo "A database error occurred"; 
} 
else if (mysqli_affected_rows($con) == 0) { 
    echo "No images waiting for " . $ToEmail . " for image " . $ToEmailDB; 
} 
else { 
    echo "Image and record deleted for " . $ToEmail . " for image " . $ToFileName . ".jpg and record " . $GuessImageID; 
} 
1

它不應該是,

"DELETE from Waiting WHERE ToUser = '" . $ToEmail . "' AND ImageID = '" . $ToEmailDB . "'" 
1
$result3 = mysqli_query($con, "DELETE FROM Waiting WHERE ToUser='".$ToEmail."' AND ImageID='".$ToEmailDB."' "); 
+0

工作正常。似乎有不止一種字符串語法的變體可行。我需要找到格式化這些查詢字符串的學習資源。 – user2431174