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.