How to Use PHP to connect to the database to implement the message board function (recommended) and the message board instance

Source: Internet
Author: User

How to Use PHP to connect to the database to implement the message board function (recommended) and the message board instance

PHP implements the message board function:

1 first, the login page:

<! DOCTYPE html> 

2. After the logon page is complete, enter the logon processing page, that is, the messloginchuli. php file submitted above.

<? Phpsession_start (); // After logging on, you need to connect the included logon page to enable session $ uid =$ _ POST ["uid"]; $ pwd = $ _ POST ["pwd"]; require_once ". /DBDA. class. php "; $ db = new DBDA (); $ SQL =" select password from yuangong where username = '{$ uid }'"; $ arr = $ db-> query ($ SQL, 0); // var_dump ($ arr [0] [0]); if ($ arr [0] [0] = $ pwd &&! Empty ($ pwd) {$ _ SESSION ["uid"] = $ uid; header ("location: message. php") ;}?>

Logon page Effect

3. After logging on to the console, you can view the dialog content you have received. The following figure shows the table and Page code of the database:

<! DOCTYPE html> 

Log out of the logon system to log out. The code for returning to the logon page is as follows:

 <?phpsession_start();$uid = $_SESSION["uid"];unset($uid);header("location:messlogin.php");?>

The code is written here, and the more important part is completed. The following is the release information page, which is equivalent to the page added previously. Its processing page is no different from the previous one, the difference is that the current processing page is operated upon user login. You need to use session to connect all the login pages.

Homepage Effect

4. Finally, the Information Publishing Page, which can send information to anyone

The Code is as follows:

<! DOCTYPE html> 

Message sending page

5. After the publishing information is complete, enter the processing page, that is, the submitted infochuli. php, and finally return the sending information interface.

<? Phpsession_start (); $ uid = $ _ SESSION ["uid"]; $ recever = $ _ POST ["recever"]; $ content = $ _ POST ["content"]; $ arr = $ _ POST ["recever"]; $ t = date ("Y-m-d H: I: s"); require_once ". /DBDA. class. php "; $ db = new DBDA (); $ SQL =" insert into liuyan values ('', '{$ uid}', '{$ t }', '{$ recever}', '{$ content}', 0) "; $ arr = $ db-> query ($ SQL); if ($ arr &&! Empty ($ arr) {header ("location: publish_info.php");} else {echo "failed to send! ";}?>

The above example of using PHP to connect to the database to implement the message board function (recommended) is all the content shared by Alibaba Cloud xiaobian. I hope you can provide a reference and support for our guests.

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.