• 例子 新闻发布


    1.新闻发布主页面

     1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     2 <html xmlns="http://www.w3.org/1999/xhtml">
     3 <head>
     4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     5 <title>无标题文档</title>
     6 <style>
     7 *{ margin:0px auto; padding:0px}
     8 </style>
     9 </head>
    10 
    11 <body>
    12 
    13 <form action="newstijiao.php" method="post">
    14     <div style="500px; height:400px; position:relative">
    15         <div style="font-size:16px; text-align:center; padding-top:20px">发布新闻</div>
    16         <div style="margin-top:20px">标题:<input name="title" type="text" style="240px; height:20px; margin-left:10px" /></div>
    17         <div style="margin-top:10px">作者:<input name="author" type="text" style="150px; height:20px; margin-left:10px" /></div>
    18         <div style="margin-top:10px">来源:<input name="source" type="text" style="150px; height:20px; margin-left:10px" /></div>
    19         <div style="margin-top:10px">内容:<input name="content" type="textarea" style="420px; height:120px; margin-left:10px" /></div>
    20 
    21     <div style="float:left; margin-left:200px"><input type="submit" value="提交" style="50px; height:30px; margin-top:10px" /></div>
    22 
    23 <form action="newsmain.php">
    24     <div style="float:left"><input type="submit" value="查看" style="margin-top:10px; 50px; height:30px; margin-left:10px" /></div>
    25 </form>
    26 </div>
    27 </form>
    28 </body>
    29 </html>

    2.新闻提交的处理界面

    <?php 
    $newsid = "";
    $title = $_POST["title"];
    $author = $_POST["author"];
    $source = $_POST["source"];
    $content = $_POST["content"];
    $time = date('y-m-d h:i:s',time());
    echo $title;
    //造连接对象
    $db = new MySQLi("localhost","root","666","newssystem");
    
    $sql = "insert into news values('{$newsid}','{$title}','{$author}','{$source}','{$content}','{$time}')";
    $db->query($sql);
    header("location:newsmain.php");

    3.页面提交至新闻列表界面

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    
    <body>
    <table width="100%" border="1" cellpadding="0" cellspacing="0">
        <tr>
            <td>newsid</td>
            <td>title</td>
            <td>Author</td>
            <td>source</td>
            <td>content</td>
            <td>time</td>
            <td>update</td>
            <td>delete</td>
        </tr>
    
    <?php 
        $db = new MySQLi("localhost","root","666","newssystem");
        $sql = "select * from news";
        $result = $db->query($sql);
        $attr = $result->fetch_all();
        foreach($attr as $v)
        {
            echo "<tr>";
            
            echo"<td>{$v[0]}</td><td>{$v[1]}</td><td>{$v[2]}</td><td>{$v[3]}</td><td>{$v[4]}</td><td>{$v[5]}</td><td><a href='newsupdate.php?c={$v[0]}')">update</a></td><td><a href='newsdelete.php?c={$v[0]}' onclick="return confirm('确定删除吗?')">delete</a></td>";
        }
        
        ?> 
    
    </table>
    </body>
    </html>

    4.删除处理界面

    <?php 
    $newsid = $_GET["c"];
    $db = new MySQLi("localhost","root","666","newssystem");
    $sql = "delete from news where newsid='{$newsid}'";
    $r = $db->query($sql);
    
    if($r)
    {
        header("location:newsmain.php");
    }
    else
    {
        echo "删除失败";
    }

    5.提交处理界面

    <?php
    $newsid = $_POST["newsid"];
    $title = $_POST["title"];
    $author = $_POST["author"];
    $source = $_POST["source"];
    $content = $_POST["content"];
    $time = date('y-m-d h:i:s',time());
    
    $db = new MySQLi("localhost","root","666","newssystem");
    
    $sql = "update news set title='{$title}',author='{$author}',source='${source}',content='${content}',time='{$time}' where newsid='{$newsid}'";
    $db->query($sql);
    header("location:newsmain.php");

    6.修改处理界面

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <style>
    *{ margin:0px auto; padding:0px}
    </style>
    </head>
    
    <body>
    
    <?php 
    $newsid = $_GET["c"];
    $db = new MySQLi("localhost","root","666","newssystem");
    $sql = "select * from news where newsid='{$newsid}'";
    
    $result = $db->query($sql);
    
    $attr = $result->fetch_all();
    foreach($attr as $a)
    {
        
    }
    
    
     
    ?>
    
    <form action="newstijiaochuli.php" method="post">
        <div style="500px; height:400px; position:relative">
            <div style="font-size:16px; text-align:center; padding-top:20px">发布新闻</div>
            <div style="margin-top:20px"><input value="<?php echo $a[0] ?>" name="newsid" type="hidden" /></div>
            <div style="margin-top:20px">标题:<input value="<?php echo $a[1] ?>" name="title" type="text" style="240px; height:20px; margin-left:10px" /></div>
            <div style="margin-top:10px">作者:<input value="<?php echo $a[2] ?>" name="author" type="text" style="150px; height:20px; margin-left:10px" /></div>
            <div style="margin-top:10px">来源:<input value="<?php echo $a[3] ?>" name="source" type="text" style="150px; height:20px; margin-left:10px" /></div>
            <div style="margin-top:10px">内容:<input value="<?php echo $a[4] ?>" name="content" type="textarea" style="420px; height:120px; margin-left:10px" /></div>
    
        <div style="float:left; margin-left:200px"><input type="submit" value="修改" style="50px; height:30px; margin-top:10px" /></div>
    
    <form action="newsmain.php">
        <div style="float:left"><input type="submit" value="查看" style="margin-top:10px; 50px; height:30px; margin-left:10px" /></div>
    </form>
    </div>
    </form>
    </body>
    </html>
  • 相关阅读:
    leetcode 104. Maximum Depth of Binary Tree 二叉树的最大深度(简单)
    leetcode 105. Construct Binary Tree from Preorder and Inorder Traversal 从前序与中序遍历序列构造二叉树(中等)
    leetcode 83. Remove Duplicates from Sorted List 删除排序链表中的重复元素(简单)
    leetcode 637. Average of Levels in Binary Tree 二叉树的层平均值(简单)
    Fiddler的安装与使用
    Redis
    开发那些事儿:如何解决js打包文件体积过大导致的网页加载慢问题?
    AI人工智能识别技术如何助力构建风险监测预警系统?
    H.265流媒体播放器EasyPlayer切换播放协议时,快照无法消失如何处理?
    AI人脸检测/行为识别智能分析网关8大智慧应用场景分析
  • 原文地址:https://www.cnblogs.com/chenshanhe/p/6861057.html
Copyright © 2020-2023  润新知