PHP开发简单新闻发布系统之新闻列表页删除功能模块
本节介绍本节介绍怎么从新闻列表页删除新闻,并且删除数据库中该新闻的记录。
我们还是离不开操作数据库,这里需要使用delete:删除数据表中的数据
思路:
通过删除数据路表new表中的id字段来删除一条新闻

SQL语句为:
<?php $sql = "delete from new where id = '$id'"; ?>
完整的实现删除功能的delete.php文件:
<?php
header("content-type:text/html;charset=utf8");
$link = mysqli_connect('localhost','root','root','test');
mysqli_set_charset($link, "utf8");
if (!$link) {
die("连接失败:".mysqli_connect_error());
}
$id = $_GET['id'];
$sql = "delete from new where id = '$id'";
//echo $sql;
$rel = mysqli_query($link,$sql);
if($rel){
echo "<script>alert('删除成功');window.location.href='list.php'</script>";
}else{
echo "<script>alert('删除失败');window.location.href='list.php'</script>";
}
?>
