簡體   English   中英

PHP PDO占位符將不會刪除

[英]PHP PDO placeholders will not DELETE

我試圖刪除表'telefoonnummers'中的一條記錄。 但是什么都沒有改變。 以下是什么錯誤?

<HTML>
  <?php
        require_once 'db_config.php';

        //get data last page
            $indexnr = $_GET['id'];

            $sth = $dbh->prepare("DELETE FROM telefoonnummers WHERE index = :indexnr");
            $sth->bindValue(':indexnr', $indexnr, PDO::PARAM_INT);
            $count = $sth->execute();

            if($count == 1) {
        print "One record deleted!<br>";
            }
            else 
            {
        print "None record deleted!";
            }
        //Back to first page
?>
        <a href="admin.php">Back</a>
</HTML>

這里似乎需要進行一些基本的調試-檢查查詢是否有效。 我沒有發現您的代碼有任何明顯的錯誤。

try {
    $count = $sth->execute();
} catch (PDOException $e) {
    // do error handling
    var_dump($e); // use only for debug
}

echo $_GET['id']; 驗證您是否正在從GET提取正確的信息。

echo $count; 驗證您在進行適當的比較。

無論哪種方式,將關鍵的PDO查詢都包含在try / catch中都是一種好習慣。

object(PDOException)#3 (8) { ["message":protected]=> string(213) "SQLSTATE[42000]: 
Syntax error or access violation: 1064 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 'index = '4'' at line 1" 

["string":"Exception":private]=> string(0) "" ["code":protected]=> string(5) "42000" ["file":protected]=> string(50) "C:\USBwebserver\root\PhpProjectWeek5\verwijder.php" ["line":protected]=> int(14) ["trace":"Exception":private]=> array(1) { [0]=> array(6) { ["file"]=> string(50) 
"C:\USBwebserver\root\PhpProjectWeek5\verwijder.php" ["line"]=> int(14) ["function"]=> string(7) "execute" ["class"]=> string(12) "PDOStatement" ["type"]=> string(2) "->" ["args"]=> array(0) { } } } ["previous":"Exception":private]=> NULL ["errorInfo"]=> array(3) { [0]=> string(5) "42000" [1]=> int(1064) [2]=> string(157) "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 'index = '4'' at line 1" } } 

注意:未定義的變量:在第21行的C:\\ USBwebserver \\ root \\ PhpProjectWeek5 \\ verwijder.php中計數沒有記錄被刪除! 背部

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM