Use PHP to connect to database for message board function

Source: Internet
Author: User
Tags button type
The following small series for everyone to bring a PHP connection to the database to implement the message board function of the example explained (recommended). Small series feel very good, now share to everyone, also for everyone to make a reference. Let's take a look at it with a little knitting.

PHP Implementation message Board function:

1 First login page:


<! DOCTYPE html>

2 Login page After completion to enter the login processing page, that is, the above submitted to the messloginchuli.php


<?phpsession_start (); After login to connect the included login page, open 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");}? >

Login page Effects

3. After the login is completed, it is to enter the main page, that is, to display the conversation you received, the following is the design of the database table and main page code:


<! DOCTYPE html>

Log out of the system to implement user logoff, return to the login page function code as follows:


<?phpsession_start (); $uid = $_session["UID"];unset ($uid); Header ("location:messlogin.php"); >

The code is written here, the more important part is completed, the following is to enter the publishing information page, the equivalent of the previous write the added page, its processing page is not the same as before, the difference is that the current processing page in the case of user login operation, You need to use the session to connect all the pages in the login situation

Main Page effects

4. Finally, the Information publishing page, you can send information to anyone

The code is as follows:


<! DOCTYPE html>

Send Information page

5. After completion of the release information to enter the processing page, which is submitted to the infochuli.php, and finally return to send the 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 value S (', ' {$uid} ', ' {$t} ', ' {$recever} ', ' {$content} ', 0) ', $arr = $db->query ($sql); if ($arr &&!empty ($arr)) { Header ("location:publish_info.php");} else{echo "Send failed!";}? >

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.