zoukankan      html  css  js  c++  java
  • 例子 新闻发布

    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>
  • 相关阅读:
    POJ 1141 括号匹配 DP
    881. Boats to Save People
    870. Advantage Shuffle
    874. Walking Robot Simulation
    文件操作
    861. Score After Flipping Matrix
    860. Lemonade Change
    842. Split Array into Fibonacci Sequence
    765. Couples Holding Hands
    763. Partition Labels
  • 原文地址:https://www.cnblogs.com/chenshanhe/p/6861057.html
Copyright © 2011-2022 走看看