• 留言板练习


    这个练习做下来发现大体的步骤怎么走怎么做基本清晰,能实现可是做的很糙,没有老师细致……好多需要判断的地方没有想到

    denglu.php

    <!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 type="text/css">
    .a  //参照老师给的效果图,所以给div加了个样式表
    {width:400px;
    height:50px;
    color:#339; 
    font-size:28px; 
    line-height:50px;
    font-weight:bold;
    }
    </style>
    
    </head>
    
    <body><form  action="dlchuli.php"method="post">//点击登录提交到处理页面,以post传值
    <div>
    <table width="400" height="150" border="1" >
    <tr > <td height="50" colspan="2" align="center"><span class="a">开发部内部留言板</span></td> </tr>
    <tr> <td align="right">用户名:</td> <td><input type="text" name="uid"/></td></tr>
    //因为需要提交所以两个文本框都给了name值 <tr> <td align="right">口令:</td> <td><input type="text" name="pwd"/></td></tr> <tr> <td colspan="2" align="center"><input type="submit" value="登录" />&nbsp;&nbsp;<input type="reset" value="复位" /></td> </tr> </table> </div> </form> </body> </html>

    dlchuli.php

    <?php
    session_start();//开启session
    $uid=$_POST["uid"];
    $pwd=$_POST["pwd"];
    include("ChaXun.class.php");
    $db=new ChaXun();
    $sql="select count(*) from yuangong where UserName='{$uid}' and PassWord='{$pwd}'";
    $r=$db->StrQuery($sql);
    if($r==1)//判断用户名是否存在
    {    $_SESSION["uid"]=$uid;//将获取到的用户名存入session
        header("location:main.php");
    }
    else
    {
        header("loacation:denglu.php");
    }
    ?>

    main.php

    <!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 type="text/css">
    .a
    {
        font-size:22px;
        font-weight:bold;
    }
    </style>
    </head>
    
    <body>
    
    <span class="a"><a href="fabu.php">发布信息</a></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <span class="a"><a href="tuichu.php">退出系统</a></span>
    <div style="font-size:24px; font-weight:bold; margin-top:20px;">留言信息:</div>
    <table width="600" border="1" >
        <tr> <td>发送人</td> <td>发送时间</td> <td>接收人</td> <td>信息内容</td> </tr>
        <?php
        session_start();
        
        if(empty($_SESSION["uid"]))//判断用户是否存在,存在获取uid
        {
            header("location:denglu.php");
            exit;
        }
        $uid = $_SESSION["uid"];
        
        
        include("ChaXun.class.php");
        $db=new ChaXun();
        $sql="select * from liuyan where Recever='{$uid}' or Recever='suoyou' ";
        $attr=$db->Query($sql);
        
        foreach($attr as $v)
        {    $sqlname = "select Name from yuangong where username='{$v[1]}'";
            $name = $db->StrQuery($sqlname);//发送者姓名
        
        //处理接收者姓名
            $jsr = "";
            if($v[2]=="suoyou")//接收为所有人时
            {
                $jsr = "所有人";
            }
            else
            {
                $sqln = "select Name from yuangong where username='{$uid}'"; 
                $jsr = $db->StrQuery($sqln);
            }
            
            
            echo"<tr> <td>{$name}</td> <td>{$v[3]}</td> <td>{$jsr}</td> <td>{$v[4]}</td> </tr>";
        }
        ?>
    </table>
    </body>
    </html>

    fabu.php

    <!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 type="text/css">
    .a
    {
        font-size:22px;
        font-weight:bold;
    }
    </style>
    </head>
    <?php
    session_start();
    
    if(empty($_SESSION["uid"]))//判断用户是否存在
    {
        header("location:denglu.php");
        exit;
    }
    
    $uid = $_SESSION["uid"];
    
    include("ChaXun.class.php");
    $db = new ChaXun();
    ?>
    <body><form action="fabuchuli.php" method="post">
    <span class="a"><a href="main.php">查看信息</a></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <span class="a"><a href="tuichu.php">退出系统</a></span>
    <div style="font-size:24px; font-weight:bold; margin-top:20px;">信息发送:</div>
    <table width="400" border="1">
        <tr> <td align="right">接收人:</td> 
        <td>      <select name="jieshou">//下拉先把所有人这种情况摘出来,再去遍历
                  <option value="suoyou">所有人</option>
                  <?php
                  $sql="select firend from firend where me='{$uid}' ";
                  $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></td>
        </tr>
        <tr> <td align="right">信息内容:</td> <td><textarea name="nr"></textarea></td></tr>
        <tr> <td colspan="2" align="center"> <input type="submit" value="发送" />&nbsp;&nbsp;&nbsp;
                               <input type="reset" value="复位" /></td> </tr>
    </table>
    </form>
    
    </body>
    </html>

    fabuchuli.php

    <?php
    session_start();
    $uid=$_SESSION["uid"];
    $jsr=$_POST["jieshou"];
    $nr=$_POST["nr"];
    $time=date("Y-m-d H:i:s",time());//格式化当前时间戳
    include("ChaXun.class.php");
    $db=new ChaXun();
    $sql="insert into liuyan values('','{$uid}','{$jsr}','{$time}','{$nr}','')";
    echo $sql;
    if($db->Query($sql,1))
    {
        header("location:fabu.php");
    }
    
    ?>

    tuichu.php

    <?php   //这个退出自己做的时候是直接超链接的登录页面,没有考虑到要unset
    session_start();
    unset($_SESSION["uid"]);
    header("location:denglu.php");
    ?>
  • 相关阅读:
    I帧/P帧/B帧---术语解释
    利用forwardInvocation实现消息重定向
    doubango地址配置
    ARC使用小结
    NSException异常处理
    Runtime of Objective-C
    perl脚本框架整理
    模块——Getopt::Long接收客户命令行参数和Smart::Comments输出获得的命令行参数内容
    Linux学习进阶示意图
    Linux——入门命令
  • 原文地址:https://www.cnblogs.com/nannan-0305/p/5532856.html
Copyright © 2020-2023  润新知