留言板案例
Posted kevin2016
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了留言板案例相关的知识,希望对你有一定的参考价值。
登录界面:
<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> <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> <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");
以上是关于留言板案例的主要内容,如果未能解决你的问题,请参考以下文章
夺命雷公狗-----React---21--小案例之心情留言板
DOM操作相关案例 模态对话框,简易留言板,js模拟选择器hover,tab选项卡,购物车案例