PHP creates a message board and php message board
The basic message board function requires three tables:
Employee table, comment table, and friend table
Create a login page:
<Form action = "drcl. php "method =" post "> <div> account: <input type =" text "name =" zhang "/> </div> <div> password: <input type = "text" name = "mi"/> </div> <input type = "submit" value = "login"/> </form>
:
Then write the processing page:
<? Phpsession_start (); // session storage data include ("db. class. php "); // reference class $ db = new db (); // creation method $ zhang =$ _ POST [" zhang "]; $ mi = $ _ POST ["mi"]; $ SQL = "select mi from yuangong WHERE zhang = '{$ zhang }'"; $ arr = $ db-> Query ($ SQL); if (! Empty ($ mi) & $ mi = $ arr &&! Empty ($ zhang) {$ _ SESSION ["zhang"] = $ zhang; // Save the account to the header ("location: zym. php ") ;}else {echo" Login Failed ";}?>
Normally, the login page only saves the session to the account.
Log on to the master page
The following is the Home Page:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<? Php session_start (); // store data if (empty ($ _ SESSION ["zhang"]) {header ("location: ddrr. php "); // prevent the website from entering exit;} $ zhang = $ _ SESSION [" zhang "]; include (".. /db. class. php "); $ db = new db (); $ SQL =" select name from yuangong WHERE zhang = '{$ zhang }'"; $ attr = $ db-> Query ($ SQL); // obtain the login name echo "
</table></body>
Only your friends or all people can be queried.
Note that the called db should be set as a global variable.
Figure:
Message Board needs to publish information:
Release information page:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<? Phpsession_start (); // store data if (empty ($ _ SESSION ["zhang"]) {header ("location: ddrr. php "); // prevent the website from entering exit;} $ zhang = $ _ SESSION [" zhang "]; include (".. /db. class. php "); $ db = new db (); $ shaoyou =" select * from firend WHERE me = '{$ zhang }'"; $ ahaoyou = $ db-> Query ($ shaoyou);?>
<Form action = "fbcl. php "method =" post "> <div> & nbsp; recipient: & nbsp; <select name = "shou"> <option value = "all"> all </option>
<?php foreach ($ahaoyou as $v) { $name = aname($v[2]); echo "<option value='{$v[2]}'>{$name}</option>"; } ?>
</Select> </div> <br/> <div> message content: & nbsp; <input type = "text" name = "lynr"/> </div> <br/> <input type = "submit" value = "send"/> <input type = "reset" value = "clear"/> </form>
<? Phpfunction aname ($ zhang) {global $ db; // you can specify global variables! If ($ zhang = "all") {// if all is received, return "all";} else {// if it is your own, query by account name $ SQL = "select name from yuangong WHERE zhang = '{$ zhang}'"; $ arr = $ db-> Query ($ SQL ); // two-dimensional array return $ arr [0] [0] ;}}?>
<A href = "zym. php"> View information </a> <a href = "ddrr. php" onclick = "return confirm ('Are you sure you want to exit this account? ') "> Log out </a> </body>
The processing page for publishing information is as follows:
<? Phpsession_start (); $ uid = $ _ SESSION ["zhang"]; include (".. /db. class. php "); $ db = new db (); $ jsr = $ _ POST [" shou "]; $ neirong = $ _ POST [" lynr "]; $ sj = date ("Y-m-d H: I: s"); $ SQL = "insert into liuyan values ('', '{$ uid }', '{$ jsr}', '{$ sj}', '{$ neirong}', 0) "; if ($ db-> Query ($ SQL, 0 )) {header ("location: zym. php ");} else {echo" Release failed! ";}
Figure:
I used the account of Xiaohua to send a message to Xiaoming:
Therefore, log on to James's account
Figure:
Yes. He received the message from Xiaohua.