后臺(tái)新聞刪除功能
先給刪除標(biāo)簽添加一個(gè)a標(biāo)簽
<a href="newsave.php?action=del&id=<?php echo $row['id']?>">刪除</a>
用于獲取get請(qǐng)求,然后在newsave.php頁(yè)面進(jìn)行處理:
添加代碼如下:
<?php elseif($action="del"){ $id=$_GET['id']; $sql="delete from news WHERE id=$id"; $result=$mysqli->query($sql); if($result){ echo "<script>alert('刪除成功!');window.location.href='newlist.php'</script>"; }else{ echo "<script>alert('刪除失敗!');</script>"; } }
效果展示: