Php implements the message board function, and php implements the message board function.

Source: Internet
Author: User

Php implements the message board function, and php implements the message board function.

This small message board function is suitable for class or internal discussions, conversations, and messages. It is very convenient, and more importantly, it does not require the Internet. It is very common for the company's management,

The message board is written as follows:

1 first, the login page:

1 <form action = "chuli. php "method =" post "> 2 <div style =" margin-left: 500px; margin-top: 200px; 3 height: 250px; width: 250px ">/* to place the login table in the middle of the page, it is more beautiful */4 

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

1 <? Php 2 session_start (); // After logon, connect the included logon page and enable session 3 include ("DADB. class. php "); 4 5 $ db = new DADB (); 6 7 $ user = $ _ POST [" username "]; 8 $ pwd = $ _ POST ["password"]; 9 10 $ SQL = "select password from yuangong where username = '{$ user }'"; 11 12 $ arr = $ db-> Query ($ SQL); 13 14 if ($ arr [0] [0] = $ pwd &&! Empty ($ pwd) 15 {16 $ _ SESSION ["username"] = $ user; 17 header ("location: main. php "); 18} 19 else20 {21 echo" Logon Failed "; 22} 23 24?>

Is the logon page

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:

<Body> <div> 

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

1 
// This is the code for publishing the page. It is similar to the Code for adding the page. <? Php <? Phpsession_start (); $ re =$ _ POST ["jsr"]; $ comment =$ _ POST ["neirong"]; $ time = date ("Y-m-d H: I: s"); // obtain the current time $ _ SESSION ["username"] = $ user; include ("DADB. class. php "); $ db = new DADB (); $ SQL =" insert into liuyan VALUES ('', '{$ user}', '{$ jsr }', '{$ time}', '{$ comment}', false) "; if ($ db-> Query ($ SQL, 0) {header (" location: main. php ") ;}else {echo" publishing failed ";}?>?>

A simple message board has been completed. When you exit, you need to clear the session and return to the logon page.

// Exit the page Code <? Phpsession_start (); unset ($ _ SESSION ["username"]); header ("location: login. php");?>

 

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.