[英]Delete specific table in Database using php
I need to delete a specific table on database using PHP code. 我需要使用PHP代码删除数据库上的特定表。 The problem is that everytime I click "delete", the whole table is deleted. 问题是,每当我单击“删除”时,整个表都会被删除。
Here is my code for delete.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>
First of all, I'm assuming you want to delete a specific row. 首先,假设您要删除特定的行。 You need to change id=id
to something like id=$id
where $id is a variable containing an integer of the row you want deleted. 您需要将id=id
更改为id=$id
,其中$ id是一个变量,其中包含要删除的行的整数。
For instance, if you wanted to delete the row that has the id 4 you would do 例如,如果您要删除ID为4的行,则可以这样做
mysqli_query($con,"DELETE FROM announcement WHERE id=4");
mysqli_query($con,"DELETE FROM announcement WHERE id=id");
shouldn't it be $id or something ? 不应该是$ id或其他东西吗? id=id is true for all records in the table! 对于表中的所有记录,id = id为true!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.