留言板练习
這個練習做下來發現大體的步驟怎么走怎么做基本清晰,能實現可是做的很糙,沒有老師細致……好多需要判斷的地方沒有想到
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="登錄" /> <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;//將獲取到的用戶名存入sessionheader("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> <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><?phpsession_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> <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="發送" /> <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"); ?>?
轉載于:https://www.cnblogs.com/nannan-0305/p/5532856.html
總結
- 上一篇: 五大媒体播放器的Android
- 下一篇: 从零开始学编程(所以说英语也是零)