zoukankan      html  css  js  c++  java
  • 2018-2-6 留言板的制作

      今天写一个关于员工内部留言板的代码:

    主要实现功能:1,登录,如果用户密码符合数据库中储存的内容,则可以登录,否则登录失败。,

           2、进入信息界面,每个人只能看到接收人为“自己”或者“所有人”的留言,其余的不显示

           3、发留言

              4、删除留言

    数据库中的两个表:1、yuangong:

    2、liuyan:

    登录界面:

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>登录界面</title>
    </head>
    
    <body>
    <!--这是登录页面,显示登录的信息-->
    <?php
        //开始
        session_start();
        if($_POST){
            //获取表单传过来的值
            $uid=$_POST["uid"];
            $pwd=$_POST["pwd"];
            //连接数据库获取用户名密码
            $db=new
                MySQLi("localhost","root","","z_lyb");
            !mysqli_connect_error() or die("连接错误");
            $db->query("set names utf8");
            //$sql语句获取yuangong表的内容
            $sql="select * from yuangong";
            //执行$sql语句
            $result=$db->query($sql);
            $attr=$result->fetch_all();
            //循环遍历结果集,判断用户名密码是否正确
            $flag=true;        //做标记
            foreach($attr as $k=>$v){
                if($v[2]==$uid&&$v[1]==$pwd){        //判断如果用户名和密码在yuangong表中可以获取到并且关系一一对应
                    header("location:index1.php?uid=$uid");
                    $flag=false;
                    break;
                }
            }
            //判断是否登录成功
            if($flag){
                echo"登录失败";
            }
        }
        $_SESSION["uid"]=$uid;  //设置超全局变量
    ?>
    <form action="#" method="post">        <!--跳转到本页,提交方式为post-->
        <table border="1">
            <tr>
                <th>开发部内部留言板</th>
            </tr>
            <tr>
                <td>用户名:<input type="text" name="uid"></td>
            </tr>
            <tr>
                <td>口令:<input type="text" name="pwd"></td>
            </tr>
        </table>
            <input type="submit" value="登录">    
            <input type="reset" value="复位">
    </form>
    </body>
    </html>

    效果如下:

    登录成功:

               

    如果用户或密码不正确,则登录失败:

    员工留言信息如图,点击“退出系统”,返回登录界面,点击“发布信息”,跳转“发信息”页面,效果如下:

    点击“查看信息”,回到“留言信息”界面。

    代码如下:

    留言信息页面:

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>主页面</title>
    </head>
    
    <body>
    <?php
        session_start();
        $uid=$_GET["uid"];
        $db=new MySQLi("localhost","root","","z_lyb");
        !mysqli_connect_error() or die("连接失败");
        $db->query("set names utf8");    //设置数据库字符集
        //获取teacher表的内容
        $sql="select * from liuyan where Recever ='$uid' or Recever ='所有人'";
        $result=$db->query($sql);        //转成结果集
        $attr=$result->fetch_all();    
    ?>
        <a href="fabu.php">发布信息</a>
        <a href="denglu.php">退出系统</a><br>
        留言信息:<br>
        <table width="100%" border="1">
            <tr>
                <th>发送人</th>
                <th>发送时间</th>
                <th>接收人</th>
                <th>信息内容</th>
                <th>操作</th>
            </tr>
            <?php
                foreach($attr as $v){ ?>
                    <tr>
                        <td><?php echo $v[1]; ?></td>
                        <td><?php echo $v[3]; ?></td>
                        <td><?php echo $v[2]; ?></td>
                        <td><?php echo $v[4]; ?></td>
                        <td><form action="delete.php" method="post">
                                <input type="hidden" name="uid" value="<?php echo $v[0]; ?>">
                                <input type="hidden" name="id" value="<?php echo $uid; ?>">
                                <button class="btn">删除</button>    <!--删除按钮-->
                            </form>
                        </td>
                    </tr>
            <?php } ?>
        </table>
    </body>
    </html>

    发布信息页面:

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>发布信息</title>
    </head>
    
    <body>
        <a href="insert.php">查看信息</a>
        <a href="denglu.php">退出系统</a><br>
        信息发送:<br>
        <form action="insert.php" method="post">
            <table width="50%" border="1">
            <tr>
                <td>接收人:</td>
                <td>
                    <select    name="jieshou">
                        <option>张三丰</option>
                        <option>周星驰</option>
                        <option>林青霞</option>
                        <option>李逍遥</option>
                    </select>
    <!--                <input type="text" >-->
                </td>
            </tr>
            <tr>
                <td>信息内容:</td>
                <td><textarea name="xinxi"></textarea></td>
            </tr>    
        </table>
            <a href="index1.php"><input type="submit" value="发送"></a>    
            <input type="reset" value="复位">
        </form>
    
    </body>
    </html>

    发布信息的处理页面:

    <?php
    //开始
    session_start(); //设置变量,存储数据 $jieshou=$_POST["jieshou"]; //接收人 $date=date("Y-m-d h:i:s");//获取日期 $xinxi=$_POST["xinxi"];//信息内容 var_dump($date); //连接数据库 $db=new MySQLi("localhost","root","","z_lyb"); !mysqli_connect_error() or die("连接失败"); //设置字符集 $db->query("set names utf8"); //$sql语句,获取数据,插入数据 $sql="insert into liuyan(Sender,Recever,Times,Comment) values('".$_SESSION["uid"]."','$jieshou','$date','$xinxi')"; $result=$db->query($sql); //执行$sql语句                超全局变量 header("location:index1.php"); ?>

    删除信息页面:

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>删除数据</title>
    </head>
    
    <body>
    <?php
        //这个页面是处理文件夹下面的删除.php
        //连接数据库
        $db=new MySQLi("localhost","root","","z_lyb");
        !mysqli_connect_error() or die("连接失败");
        $db->query("set names utf8");
        $uid=$_POST["uid"];
        $id=$_POST["id"];
        //$sql语句删除Ids='$uid'这一行的数据
        $sql="delete from liuyan where Ids='$uid'";
        //执行$sql语句
        $result=$db->query($sql); 
        //跳转到index1.php页面
        header("location:index1.php?uid=$id");
    ?>                  传值回index1.php
    </body>
    </html>
  • 相关阅读:
    【打印】windows打印控件,Lodop.js介绍
    【MySQL】MySQL查询数据库各表的行数
    【MySQL】MySQL中查询出数据表中存在重复的值list
    【php】php5.0以上,instanceof 用法
    日期转换:Cannot format given Object as a Date (SimpleDateFormat的parse和format)
    Groovy 正则表达式 匹配点号
    什么是开发框架
    SoapUI 增大使用内存
    Groovy API link
    Groovy 跳出each循环
  • 原文地址:https://www.cnblogs.com/dns6/p/8424124.html
Copyright © 2011-2022 走看看