PHP開(kāi)發(fā)簡(jiǎn)單新聞發(fā)布系統(tǒng)之新聞列表頁(yè)刪除功能模塊
本節(jié)介紹本節(jié)介紹怎么從新聞列表頁(yè)刪除新聞,并且刪除數(shù)據(jù)庫(kù)中該新聞的記錄。
我們還是離不開(kāi)操作數(shù)據(jù)庫(kù),這里需要使用delete:刪除數(shù)據(jù)表中的數(shù)據(jù)
思路:
通過(guò)刪除數(shù)據(jù)路表new表中的id字段來(lái)刪除一條新聞
SQL語(yǔ)句為:
<?php $sql = "delete from new where id = '$id'"; ?>
完整的實(shí)現(xiàn)刪除功能的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>"; } ?>