[英]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.