• 从零开始学安全(二十三)●用PHP编写留言板


    <?php 
    include("test.php");
    ?>
    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-type=text/html;charset=utf-8"/>
    <title>留言板</title>
     <link href="NewFile" rel="SHORTCUT ICON">
    </head>
    <body>
    <a href="select.php">查看留言</a>
    <form action="add.php" method="post">
     用户 <input type="text" size="10" name="user" /> <br/>
    标题 <input type="text" name="title"><br/>
     内容 :<textarea name="content"> </textarea><br/>
     <input type="submit"  name="submit" value="发送" >
    </form>
    <table class="imagetable">
    <tr>
            <th>用户</th>
             <th>姓名</th>
            <th>内容</th>
            <th>时间</th>
            <th>操作</th>
        </tr>
    <?php 
    $sql="select * from msg order by id desc";
     $result= $conn->query($sql);
    if ($result->num_rows > 0) {
        while($row=$result->fetch_assoc()) {
            echo 
            " <tr><td>".$row["user"]."</td><td>".$row["tile"]."</td><td>".$row["content"]."</td><td>".$row["lastdate"]."</td>
      <td><a href='del.php?id=".$row["id"]."'>删除</a></td></tr>";
        }
    } else {
        echo "0 结果";
    }
    ?>        
     </table>
    
    </body>
    </html>

    主页面

    <?php
    //$sqlconne=  mysql_connect("localhost","root","root","bbs");
    //mysql_query("set names 'utf8'");//使用utf-8编码
    // 创建连接
    $conn = new mysqli("localhost","root", "root", "bbs");
    // 检测连接
    if ($conn->connect_error) {
        die("连接失败: " . $conn->connect_error);
    }
    
    
    ?>

    服务器连接页面

    <?php
    include("test.php");
    $user=$_POST['user'];
    $title=$_POST['title'];
    $content=$_POST['content'];
    if ($_POST['submit']) {
      $sql="insert into msg
          values('','$user','$title','$content',now())";
      echo '<meta http-equiv="Content-type=text/html;charset=utf-8"/>';
      if ($conn->query($sql) === TRUE) {
            echo "<script>alert('发布成功');location.href='index.php';</script>";
      } else {
          echo "Error: " . $sql . "<br>" . $conn->error;
      }
    }
    ?>

    添加留言功能

    <?php
    include("test.php");
    $user=$_GET['id'];
    $sql="delete from msg where id=".$user;
        echo '<meta http-equiv="Content-type=text/html;charset=utf-8"/>';
        if ($conn->query($sql) === TRUE) {
            echo "<script>alert('删除成功');location.href='index.php';</script>";
        } else {
            echo "Error: " . $sql . "<br>" . $conn->error;
        }
    ?>

    删除留言功能

  • 相关阅读:
    vue基础知识
    制作离线yum源
    mysql字符集
    confluence 容器版 搭建部署
    iptables和ipvs
    http状态码
    运维相关网站博客集合
    搭建nexus私有maven私服
    MySQL 常见错误代码说明
    nc(瑞士军刀)
  • 原文地址:https://www.cnblogs.com/feizianquan/p/10542997.html
Copyright © 2020-2023  润新知