PHP開發(fā)之留言板之刪除
刪除留言
提示:刪除留言里面涉及的有權(quán)限的管理,所以刪除留言的權(quán)限是只有管理員才有的,不是每個(gè)人都能有權(quán)限刪除,但是本章節(jié)是給大家展示怎么刪除留言,不涉及權(quán)限
刪除留言其實(shí)就是刪除我們數(shù)據(jù)庫(kù)里的數(shù)據(jù)
我們前面在刪除鏈接之前傳入了每個(gè)留言的 id?
<td><a?href="ressage_delete.php?id=<?php?echo?$row['id']?>"?>刪除</a>?</td>
所以在PHP頁(yè)面接收id,然后在刪除相關(guān)的id,就可以實(shí)現(xiàn)刪除的功能了
代碼如下
<?php header("content-type:text/html;charset=utf-8"); $conn=mysqli_connect("localhost","root","root","ressage"); $id=$_GET['id']; if($conn){ $sql="delete from ressage_user where id ='$id' "; $que=mysqli_query($conn,$sql); if($que){ echo"<script>alert('刪除成功,返回首頁(yè)');location.href='ressage.php';</script>"; }else{ echo "<script>alert('刪除失敗');location='" . $_SERVER['HTTP_REFERER'] . "'</script>"; exit; } }die("數(shù)據(jù)庫(kù)連接失敗" .mysqli_connect_error()); ?>