PHP開發 留言板教學之留言板刪除留言PHP頁面
刪除留言其實就是刪除我們資料庫裡的資料
我們前面在刪除連結之前傳入了每個資料的id
<td><a href ="ressage_delete.php?id=<?php echo $row['id']?>" >刪除</a> </td>
#所以在PHP頁面接收id,然後在刪除相關的id,就可以實作刪除的功能了

程式碼如下
<?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('删除成功,返回首页');location.href='ressage.php';</script>";
}else{
echo "<script>alert('删除失败');location='" . $_SERVER['HTTP_REFERER'] . "'</script>";
exit;
}
}die("数据库连接失败" .mysqli_connect_error());
?>
新建檔案
<?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('删除成功,返回首页');location.href='ressage.php';</script>";
}else{
echo "<script>alert('删除失败');location='" . $_SERVER['HTTP_REFERER'] . "'</script>";
exit;
}
}die("数据库连接失败" .mysqli_connect_error());
?>
預覽
Clear
- 課程推薦
- 課件下載
課件暫不提供下載,工作人員正在整理中,後期請多關注該課程~ 













