首页 > 代码库 > 11月8日PHP练习《留言板》
11月8日PHP练习《留言板》
三、网页代码及网页显示
1.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"> *{ margin:0px auto; padding:0px} #aa{ width:400px; height:89px; font-size:36px; color:#39F; text-align:center; line-height:89px; vertical-align:middle; border-bottom:1px solid #999} .bb{ width:400px; height:59px} .cc{ width:159px; height:59px; float:left; font-size:20px; text-align:right; line-height:59px; vertical-align:middle} .dd{ width:200px; height:59px; float:left} .ee{ width:150px; height:30px; text-align:center; margin-top:15px} .ff{ width:80px; height:30px} </style> </head> <body> <form action="dengluchuli.php" method="post"> <div style="width:400px; height:259px; margin-top:100px; border:1px solid #999"> <div id="aa">汉企网络0904留言板</div> <div class="bb"> <div class="cc">用户名:</div> <div class="dd"><input id="yonghuming" class="ee" type="text" name="uid" /></div> </div> <div class="bb"> <div class="cc">密码:</div> <div class="dd"><input class="ee" type="password" name="pwd" /></div> </div> <div style="width:400px; height:50px; text-align:center; margin-top:10px"> <input class="ff" type="submit" value="登录" /> <input class="ff" type="button" value="复位" onclick="Fuwei()" /> </div> </div> </form> </body> <script type="text/javascript"> function Fuwei() { document.getElementById("yonghuming").value = ""; } </script> </html>
2.dengluchili.php 登录处理页面
<?php session_start(); $UserName = $_POST["uid"]; $PassWord = $_POST["pwd"]; include("DBDA.class.php"); $db = new DBDA(); $sql = "select PassWord from yuangong where UserName=‘$UserName‘"; $mm = $db->StrQuery($sql); if($PassWord !="" && $PassWord==$mm) { $_SESSION[‘views‘]=$UserName; header("location:main.php"); } else { echo "用户名或密码输入错误"; }
3.main.php 主页面,显示所有的信息。
<?php session_start(); ?> <!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> </head> <body> <?php include("DBDA.class.php"); $db = new DBDA(); $sall = "select count(*) from liuyan"; $total = $db->StrQuery($sall); include("../page.class.php"); $page = new Page($total,20); $sql = "select * from liuyan ".$page->limit; $result = $db->Query($sql); foreach($result as $v) { } ?> <br /> <div><a href="fabuxinxi.php">发布信息</a> <a href="tuichuchuli.php">退出系统</a></div> <br /> <table width="50%" border="1" cellpadding="0" cellspacing="0"> <tr> <td>发送人</td> <td>接收人</td> <td>发送时间</td> <td>信息内容</td> </tr> <?php foreach($result as $v) { echo "<tr><td>$v[1]</td><td>$v[2]</td><td>$v[3]</td><td>$v[4]</td></tr>"; } ?> </table> <?php echo $page->fpage();//显示表格下方的数据和页面的信息。 if(empty($_SESSION["views"])) { header("location:denglu.php"); exit; } ?> </body> </html>
4.fabuxinxi.php 发布信息页面
<?php session_start(); ?> <!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"> *{ margin:0px; padding:0px} .aa{ width:300px; height:40px; border:2px solid #999; border-bottom:0px; text-align:center; line-height:40px; vertical-align:middle} .bb{ width:80px; height:30px} #text1{ float:left; margin-top:10px; width:150px; height:20px; margin-left:2px} </style> </head> <body> <form action="fabuxinxichuli.php" method="post" onclick="return true"> <div style="position:relative; left:100px; top:40px"> <div><a href="chakanxinxi.php">查看信息</a> <a href="tuichuchuli.php">退出系统</a></div> <br /> <div class="aa"> <div style="float:left; width:100px; height:40px; text-align:right">接收人:</div> <!--<input id="text1" type="text" name="jieshouren" />--> <select name="jishouren" style="width:100px; height:25px; margin-top:8px; margin-left:-100px"> <option selected="selected">所有人</option> <?php include("DBDA.class.php"); $db = new DBDA(); $sql = "select firend from firend"; $result = $db->Query($sql); foreach($result as $v) { echo "<option>$v[0]</option>"; } ?> </select> </div> <div class="aa" style="height:90px"> <div style="float:left; width:100px; height:90px; text-align:right; line-height:90px; vertical-align:middle">信息内容:</div> <div style="text-align:left"><textarea id="text2" name="xinxineirong" style="margin-top:4px; height:80px"></textarea></div> </div> <div class="aa" style="border-bottom:2px solid #999"> <input class="bb" type="submit" value="发送" /> <input class="bb" type="button" value="复位" onclick="Fuwei()" /> </div> </div> </form> <?php if(empty($_SESSION["views"])) { header("location:denglu.php"); } ?> </body> <script type="text/javascript"> function Fuwei() { document.getElementById("text1").value = ""; document.getElementById("text2").value = ""; } </script> </html>
5.fabuxinxichuli.php 发布信息处理页面
<?php session_start(); $fasongren = $_SESSION[‘views‘]; $time = date("Y-m-d h:i:s"); $jieshouren = $_POST["jieshouren"]; $xinxineirong = $_POST["xinxineirong"]; include("DBDA.class.php"); $db = new DBDA(); $sql ="insert into liuyan values(‘‘,‘{$fasongren}‘,‘{$jieshouren}‘,‘{$time}‘,‘{$xinxineirong}‘)"; $db->Query($sql,0); if(empty($_SESSION["views"])) { header("location:denglu.php"); } else { header("location:main.php"); }
6.chakanxinxi.php 只显示和登陆者有关系的信息
<?php session_start(); ?> <!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> </head> <body> <?php $sender = $_SESSION[‘views‘]; $Recever = $_SESSION[‘views‘]; include("DBDA.class.php"); $db = new DBDA(); $sall = "select count(*) from liuyan"; $total = $db->StrQuery($sall); include("../page.class.php"); $page = new Page($total,20); $sql = "select * from liuyan where Sender=‘$sender‘ or Recever=‘$Recever‘ ".$page->limit; $result = $db->Query($sql); foreach($result as $v) { } ?> <br /> <div><a href="http://www.mamicode.com/fabuxinxi.php">返回</a></div> <br /> <table width="50%" border="1" cellpadding="0" cellspacing="0"> <tr> <td>发送人</td> <td>接收人</td> <td>发送时间</td> <td>信息内容</td> </tr> <?php foreach($result as $v) { echo "<tr><td>$v[1]</td><td>$v[2]</td><td>$v[3]</td><td>$v[4]</td></tr>"; } ?> </table> <?php echo $page->fpage();//显示表格下方的数据和页面的信息。 if(empty($_SESSION["views"])) { header("location:denglu.php"); exit; } ?> </body> </html>
7.tuichuchuli.php 退出系统,清空session。
<?php session_start(); unset($_SESSION); session_destroy(); header("location:denglu.php");
11月8日PHP练习《留言板》
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。