PHP開發企業網站教學刪除新聞資訊
點選刪除跳到delnews.php 檔案
下面我們來看下這個檔案的程式碼:
<?php
//删除新闻资讯部分代码
require_once('conn.php');
$id = $_GET['id'];
$sql = "delete from news where id='$id'";
$res = mysql_query($sql);
if($res){
echo "<script>alert('删除成功');location.href='news.php';</script>";
}else{
echo "<script>alert('删除失败');location.href='news.php';</script>";
}
?>連結資料庫,取得表單帶過來的參數 id 然後寫sql 語句進行刪除
執行sql 語句刪除成功,跳轉展示頁面,這樣我們可以在展示頁面進行查看
新建檔案
<?php
//删除新闻资讯部分代码
require_once('conn.php');
$id = $_GET['id'];
$sql = "delete from news where id='$id'";
$res = mysql_query($sql);
if($res){
echo "<script>alert('删除成功');location.href='news.php';</script>";
}else{
echo "<script>alert('删除失败');location.href='news.php';</script>";
}
?>
預覽
Clear
- 課程推薦
- 課件下載
課件暫不提供下載,工作人員正在整理中,後期請多關注該課程~ 





![ThinkPHP5快速開發企業網站[全程實錄]](https://img.php.cn/upload/course/000/000/068/6253d918a3ce7278.png)









