PHP開發(fā) 新聞發(fā)布系統(tǒng)之新聞刪除頁面
創(chuàng)建?new_del.php 文件
我們在新聞列表頁面已經(jīng)以get的形式傳了每條數(shù)據(jù)的id
<a?href="new_del.php?id=<?php?echo?$row['id']?>">刪除</a>
我們在修改頁面只要接收這個(gè)id,然后再把數(shù)據(jù)庫的數(shù)據(jù)刪掉就好了
代碼如下
<?php header("content-type:text/html;charset=utf-8"); $id=$_GET['id']; $conn=mysqli_connect("localhost","root","root","News"); if($conn){ $sql="delete from new where id ='$id' "; $que=mysqli_query($conn,$sql); if($que){ echo"<script>alert('刪除成功,返回首頁');location.href='new_list.php';</script>"; }else{ echo "<script>alert('刪除失敗');location='" . $_SERVER['HTTP_REFERER'] . "'</script>"; exit; } }die("數(shù)據(jù)庫連接失敗" .mysqli_connect_error()); ?>
這樣就把我們的刪除功能完成了
將前面的章節(jié)結(jié)合起來,我們就完成了一個(gè)最簡單的新聞發(fā)布系統(tǒng)