我试图在表'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查询包裹在尝试/捕获中。
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:USBwebserverrootPhpProjectWeek5verwijder.php" ["line":protected]=> int(14) ["trace":"Exception":private]=> array(1) { [0]=> array(6) { ["file"]=> string(50)
"C:USBwebserverrootPhpProjectWeek5verwijder.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" } }
注意:未定义的变量:c: usbwebserver root root phpprojectweek5 verwijder.php在第21行21 没有记录已删除!