PHP creates a message board and php message board

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.