亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

PHP開發(fā)新聞管理系統(tǒng)之刪除功能的實(shí)現(xiàn)

之前我們曾講過展示頁面,修改刪除都帶了一個輸出id的語句,程式碼去下:

<a href="modifynew.php?id=<?php echo $ row['id'];?>">修改</a>

#<a href="delnew.php?id=<?php echo $row['id']; ?>">刪除</a>

可以看出,點(diǎn)擊刪除,跳到delnew.php 頁面

注意:刪除,我們也是要取得id,然後在資料庫進(jìn)行查詢,寫刪除語句,必須要有條件,不然就不知道刪除哪條資料了

刪除功能的流程圖:

del.png

首先連接資料庫

????header("Content-type: text/html; charset=utf-8");//設(shè)定編碼
?? ?$con =@mysql_connect("localhost","root","root ") or die("資料庫連線失敗");
?? ?mysql_select_db('news') or die("指定的資料庫無法開啟");
?? ?mysql_query("set names utf8");//設(shè)定資料庫的字元集

然後取得id

$id = $_GET['id'];

最後我們寫刪除語句

????$sql = "delete from new where id='$id'";
?? ?$res = mysql_query($sql);
?? ?if($res){
?? ??? ?echo "<script>alert#?? ??? ?echo "<script>alert#?? ???.href='newlist.php';</script>";
?? ?}else{
?? ??? ?echo "<script>alert('刪除失敗');location.href='newlist.php;script>alert('刪除失敗');location.href='newlist.php';<list.php';<list.php';<list.php'; ;/script>";
?? ?}

這樣我們的刪除功能就已經(jīng)實(shí)現(xiàn)了


完整程式碼如下

<?php
    header("Content-type: text/html; charset=utf-8");//設(shè)置編碼
    $con =@mysql_connect("localhost","root","root") or die("數(shù)據(jù)庫連接失敗");
    mysql_select_db('news') or die("指定的數(shù)據(jù)庫不能打開");
    mysql_query("set names utf8");//設(shè)置數(shù)據(jù)庫的字符集

    $id = $_GET['id'];
    
    $sql = "delete from new where id='$id'";
    $res = mysql_query($sql);
    if($res){
        echo "<script>alert('刪除成功');location.href='newlist.php';</script>";
    }else{
        echo "<script>alert('刪除失敗');location.href='newlist.php';</script>";
    }
?>
繼續(xù)學(xué)習(xí)
||
<?php header("Content-type: text/html; charset=utf-8");//設(shè)置編碼 $con =@mysql_connect("localhost","root","root") or die("數(shù)據(jù)庫連接失敗"); mysql_select_db('news') or die("指定的數(shù)據(jù)庫不能打開"); mysql_query("set names utf8");//設(shè)置數(shù)據(jù)庫的字符集 $id = $_GET['id']; $sql = "delete from new where id='$id'"; $res = mysql_query($sql); if($res){ echo "<script>alert('刪除成功');location.href='newlist.php';</script>"; }else{ echo "<script>alert('刪除失敗');location.href='newlist.php';</script>"; } ?>
提交重置程式碼