我需要使用PHP代码删除数据库上的特定表。问题是每次我点击“删除”,整个表都会被删除。
以下是delete.php
的代码:
<?php
$con=mysqli_connect("localhost","root","","neust");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($con,"DELETE FROM announcement WHERE id=id");
mysqli_close($con);
?>
<script>alert("Deleted");document.location="Announcement.php"</script>
答案 0 :(得分:1)
首先,我假设您要删除特定行。您需要将id=id
更改为id=$id
,其中$ id是包含要删除的行的整数的变量。
例如,如果您想要删除具有id 4的行,那么
mysqli_query($con,"DELETE FROM announcement WHERE id=4");
答案 1 :(得分:0)
mysqli_query($con,"DELETE FROM announcement WHERE id=id");
不应该是$ id或者什么?对于表中的所有记录,id = id为true!