我对使用PHP和MySQL进行的项目有疑问。 我想从文档中删除一行,但不能删除。 这很奇怪,因为当我单击“删除”按钮时,他进入了index.php,但是它没有从数据库中删除该行。
if(isset($_POST['delete'])){
$sql = "DELETE FROM account WHERE idAccount = '".$id."'";
$result = $conn->query($sql);
header("location: index.php");
}
答案 0 :(得分:-1)
尝试一下,您在'
之后插入了".$id."
if(isset($_POST['delete'])){
$sql = "DELETE FROM account WHERE idAccount = ".$id."";
$result = $conn->query($sql);
header("location: index.php");
}
或
if(isset($_POST['delete'])){
$sql = "DELETE FROM account WHERE idAccount = '".$id."'";
$result = $conn->query($sql);
header("location: index.php");
}
答案 1 :(得分:-2)
@ nico-haase已经提到您的陈述是错误的:
$sql = "DELETE FROM account WHERE idAccount = ".$id."'";
评估为(检查尾随报价):
DELETE FROM account WHERE idAccount = NUMBER'
此外,我同意@ramraider,这是这里的一个大型sql注入。您应该至少清理输入内容(int $_POST['id']
或最好使用PDO。