zoukankan      html  css  js  c++  java
  • 留言板案例

    登录界面:


    <body> <h1>登录界面</h1> <form action="chuli.php" method="post"> <div > 开发部内部留言板 </div> <div >用户名:<input type="txt" name="yh" /></div> <div >口令:<input type="txt" name="mm" /></div> <div ><input type="submit" value="登录" /> <input type="reset" value="复位" /></div> </form> </body>





    chuli.php
    <?php
    session_start();
    $username = $_POST["yh"];
    $password = $_POST["mm"];
    
    include("../DBDA.class.php");
    $db = new DBDA();
    $sql = "select count(*) from yuangong where username = '{$username}' and password = '{$password}'";
    $r = $db->StrQuery($sql);
    if($r==1)//判断用户名,密码是否存在
    {
        $_SESSION["username"] = $username;
        header("location:main.php");
    }
    else
    {
        header("location:log.php");
    }






    主界面:main.php
    <body>
    <a href="xinxi.php">发布消息</a>&nbsp;&nbsp;
    <a href="tuichu.php">退出系统</a>
    <h1>留言信息:</h1>
    <table width="100%" border="1" cellpadding="0" cellspacing="0">
    <tr><td>发送人</td><td>发送时间</td><td>接收人</td><td>信息内容</td></tr>
    
    <?php
    session_start();
    if(empty($_SESSION["username"]))
    {
        header("location:log.php");
        exit;
    }
    
    $username = $_SESSION["username"];
    
    include("../DBDA.class.php");
    $db = new DBDA();
    $sql = "select * from liuyan where recever='{$username}' or recever='suoyou'";
    $attr = $db->Query($sql);
    
    foreach($attr as $v)
    {
        //处理发送者姓名
        $sqlname = "select Name from yuangong where username='{$v[1]}'";
        $name = $db->StrQuery($sqlname);
        //处理接收者姓名
        $jieshou = "";
        if($v[2]=="suoyou")
        {
            $jieshou = "所有人";
        }
        else
        {
        $sqln = "select Name from yuangong where username='{$username}'";
        $jieshou = $db->StrQuery($sqln);
        }
        
        echo "<tr><td>{$name}</td><td>{$v[3]}</td><td>{$jieshou}</td><td>{$v[4]}</td></tr>";  
    }
    
    
    ?>
    </table>
    </body>





    留言板页面:xinxi.php
    <body>
    <?php
    session_start();
    if(empty($_SESSION["username"]))
    {
        header("location:log.php");
        exit;
    }
    
    $username = $_SESSION["username"];
    
    include("../DBDA.class.php");
    $db = new DBDA();
    
    
    ?>
    <a href="main.php">查看信息</a>&nbsp;&nbsp;
    <a href="tuichu.php">退出系统</a>
    <h1>信息发送</h1>
    <form action="xinxichuli.php" method="post">
    <div>接收人:
        <select name="jieshou">
        <option value="suoyou">所有人</option>
        <?php
        $sql = "select friend from friend where me='{$username}'";
        $attr = $db->Query($sql);
        foreach($attr as $v)
        {
            $sqln = "select name from yuangong where username='{$v[0]}'";
            $name = $db->StrQuery($sqln);
            echo "<option value='$v[0]'>{$name}</option>";
        }
        
        
        
        
        ?>
        
        </select>
    
    </div>
    
    <div>
        信息内容:
        <textarea name="xinxi">
        
        
        </textarea>
    
    </div>
    <div>
        <input type="submit" value="发送" />
        <input type="reset" value="复位" />
    </div>
    </form>
    
    
    
    </body>





    xinxichuli.php;
    <?php
    session_start();
    
    include("../DBDA.class.php");
    $db = new DBDA();
    
    $jieshou = $_POST["jieshou"];
    $xinxi = $_POST["xinxi"];
    
    $username = $_SESSION["username"];
    
    $time = date("Y-m-d H:i:s");
    
    $sql = "insert into liuyan values ('','{$username}','{$jieshou}','{$time}','{$xinxi}','')";
    
    if($db->Query($sql,0))
    {
        header("location:xinxi.php");
    }
    else
    {
        echo "发布失败";
    }






    tuichu.php
    <?php
    session_start();
    unset($_SESSION["username"]);
    header("location:log.php");
  • 相关阅读:
    [ Linux ] rsync 对异地服务器进行简单同步
    [ Skill ] 遍历整个项目设计的两个思路
    [ Skill ] 不常用的函数笔记
    [ Perl ] Getopt 使用模板
    [ Skill ] 两个 listBox 数据交换的模板
    [ Linux ] "真"后台 nohup
    [ VM ] VirtualBox 压缩 .vdi
    [ Skill ] Layout 工艺移植,还原库调用关系
    win8 hyper-v 禁用不必卸载虚拟机
    BM算法解析(计算机算法-设计与分析导论(第三版))
  • 原文地址:https://www.cnblogs.com/kevin2016/p/5537966.html
Copyright © 2011-2022 走看看