Three tables used in the database
I. Login interface (denglu.php login.php)
1.denglu.php
1<! DOCTYPE html>234<meta charset= "UTF-8" >5<title></title>67 8<body>9Ten<form action= "login.php" method= "POST" > One<div> Username: <input type= "text" name= "UserName"/></div> A<div> Password: <input type= "password" name= "password"/></div> -<input type= "Submit" value= "Login"/> -<a href= "denglu.php" style= "Text-decoration:none" ><input type= "button" value= "Reset"/></a> the</form> -</body> -
2.login.php
1<?PHP2 Session_Start();3 $UserName=$_post["UserName"];4 $PassWord=$_post["PassWord"];5 6 require"DBDA.class1.php";7 $db=NewDbda ();8 $sql= "Select PassWord from yuangong where UserName = ' {$UserName}‘";9 $arr=$db->query ($sql);Ten One if(Count($arr)) A { - if($arr[0] [0] = =$PassWord&&!Empty($PassWord)) - { the //Store User name - $_session["UserName"] =$UserName; - - Header("location:main.php"); + } - } + Else A { at Header("location:denglu.php"); -}
Two. Main interface (main.php tuichu.php)
1.main.php
1<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >234<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>5<title> Untitled Document </title>67 8<body>9<?PHPTen Session_Start(); One A //prevent bypassing the login directly into the main interface - if(Empty($_session["UserName"])) - { the Header("location:denglu.php"); - Exit; - } - + require"DBDA.class1.php"; - $db=NewDbda (); + $UserName=$_session["UserName"]; A?> at<div> -<a href= "fabu.php" > Release information </a> -<a href= "tuichu.php" > Exit system </a> -</div><br/><br/> - -<table width= "100%" border= "1" > in<tr> -<td> Senders </td> to<td> Send Time </td> +<td> Receivers </td> -<td> Information Content </td> the</tr> *<?PHP $ Panax Notoginseng //Show the recipient is mine, or everyone's. - $sql= "SELECT * from Liuyan where recever= ' {$UserName} ' or recever= ' suoyou ' "; the $arr=$db->query ($sql); + foreach($arr as $v) A { the + Echo"<tr> -<td>{$v[1]}</td> $<td>{$v[3]}</td> $<td>{$v[2]}</td> -<td>{$v[4]}</td> -</tr> "; the } - Wuyi?> the -</table> Wu</body> -
2.tuichu.php
1 <? PHP 2 3 Session_Start (); 4 5 unset ($_session["UserName"]); 6 7 Header ("location:denglu.php");
Three. Send page (fabu.php fabuchuli.php)
1.fabu.php
1<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >234<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>5<title> Untitled Document </title>67 8<body>9<div>Ten<a href= "main.php" > View info </a> One<a href= "tuichu.php" > Exit system </a> A</div> - -<form action= "fabuchuli.php" method= "POST" > the<div>Receiving Person: -<select name= "JSR" > -<option value= "Suoyou" > Everyone </option> -<?PHP + Session_Start(); - $UserName=$_session["UserName"]; + require"DBDA.class1.php"; A $db=NewDbda (); at //Method One - $sql= "Select Friend." Friend,yuangong. Name from Friend,yuangong where friend. Friend = Yuangong. UserName and friend. Me = ' {$UserName}‘"; - $arr=$db->query ($sql); - - foreach($arr as $v) - { in Echo"<option value= ' {$v[0]} ' >{$v[1]} </option> "; - } to //Method Two + /*$sql = "Select friend from friend where Me = ' {$UserName} '"; - $arr = $db->query ($sql); the foreach ($arr as $v) * { $ $v [0];Panax Notoginseng $sname = "Select Name from yuangong where UserName = ' {$v [0]} '"; - $aname = $db->query ($sname); the echo "<option value= ' {$v [0]} ' >{$aname [0][0]}</option>"; + }*/ A?> the</select></div> +<div> Information content: <textarea name= "Neirong" ></textarea></div> -<input type= "Submit" value= "Send"/> $<a href= "fabu.php" style= "Text-decoration:none" ><input type= "button" value= "Reset"/></a> $</form> -</body> -
2.fabuchuli.php
1<?PHP2 Session_Start();3 $UserName=$_session["UserName"];4 $JSR=$_post["JSR"];5 $nr=$_post["Neirong"];6 $Times=Date("Y-m-d h:i:s");7 8 9 require"DBDA.class.php";Ten $db=NewDbda (); One $sql= "INSERT into Liuyan values ('", ' {$UserName}‘,‘{$JSR}‘,‘{$Times}‘,‘{$nr}‘)"; A $db->query ($sql, 0); - Header("location:fabu.php");
PHP Session Control Example: Message board