PHP開發企業網站教學修改新聞資訊

點擊修改頁面跳到modifnew.php頁面

來看下modifynew.php 的頁面

<?php
    require_once('conn.php');
    $id = $_GET['id'];
    $sql = "SELECT * from news where id='$id'";
    $res = mysql_query($sql);
    $row = mysql_fetch_array($res);
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改新闻资讯</title>
    <style type="text/css">
        .ipt{width:180px;height:30px;border-radius:5px;
            outline:none;border:1px solid #eee;box-sizing:border-box;padding-left:15px;}
        .sub{width:50px;height:20px;border:1px solid #eee;background:#eee;color:#ff7575;}
    </style>
</head>
<body>
    <form method="post" action="modifynews.php?id=<?php echo $id;?>">
        标题:<input type="text" name="title" class="ipt" value="<?php echo $row['title'];?>">
        </br></br>
        内容:<textarea cols="80" rows="10" name="content" class="txt"><?php echo $row['content'];?></textarea></br></br>
        类型:<select name="type">
                <option value="0">公司公告</option>
                <option value="1">公司新闻</option>
              </select></br></br>
        <input type="submit" value="修改" class="sub">
    </form>
</body>
</html>

表單提交到modifynews.php  頁面,也帶有一個參數id

我們來看以下modifynews.php這個頁面

程式碼如下:

<?php
    require_once('conn.php');
    $id = $_GET['id'];
    $title = $_POST['title'];
    $type = $_POST['type'];
    $content = $_POST['content'];
    $newtime = time();

    $sql = "UPDATE news SET title='$title',content='$content',type='$type',newtime='$newtime' where id='$id'";
    $res = mysql_query($sql);
    if($res){
        echo "<script>alert('修改新闻资讯成功');location.href='news.php'</script>";
    }else{
        echo "<script>alert('修改新闻资讯失败');history.go(-1);</script>";
    }
?>

如上程式碼,我們就已經完成了修改新聞的功能

繼續學習
||
<?php require_once('conn.php'); $id = $_GET['id']; $sql = "SELECT * from news where id='$id'"; $res = mysql_query($sql); $row = mysql_fetch_array($res); ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>修改新闻资讯</title> <style type="text/css"> .ipt{width:180px;height:30px;border-radius:5px; outline:none;border:1px solid #eee;box-sizing:border-box;padding-left:15px;} .sub{width:50px;height:20px;border:1px solid #eee;background:#eee;color:#ff7575;} </style> </head> <body> <form method="post" action="modifynews.php?id=<?php echo $id;?>"> 标题:<input type="text" name="title" class="ipt" value="<?php echo $row['title'];?>"> </br></br> 内容:<textarea cols="80" rows="10" name="content" class="txt"><?php echo $row['content'];?></textarea></br></br> 类型:<select name="type"> <option value="0">公司公告</option> <option value="1">公司新闻</option> </select></br></br> <input type="submit" value="修改" class="sub"> </form> </body> </html>
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!