Make a message board with PHP

Source: Internet
Author: User
Tags date format insert interface sql mysql php programming php script
We can see all kinds of message boards on many websites, which is one of the main means of communication between website and visitor. A reasonable design, the interface beautiful message board program can reflect the site from the side of good service, to visitors to leave a good impression, enhance the user's confidence in the site. The message board from the procedural point of view is actually very simple, difficult in the unadorned function of the creative performance. Below we only use PHP script program as an example, from the point of view of the program how to make walls.
The principle of message board implementation is generally two kinds, namely file type and database type. They are differentiated by the way message information is stored in the server. Because the file-type message system is not competent for multi-user, large capacity of information processing and query services, so a good ductility of the database drive is a lot of transaction processing applications.   Below we use PHP, MySQL system for the platform to build a basic walls. The basic message board by the message fills in, saves, displays, the management and so on the program composition, the structure is very simple, but involves the php+mysql structure most operations, is we learn the PHP programming the excellent introduction practice.
1. Database structure:
Message number ID int auto Increment
Message name varchar 20 up to 20 characters
Message time msgdate datetime date type
e-mail Email varchar 40 up to 40 characters
Message content msg Text type
This is a simple message storage model library, according to the design needs can also add some fields, such as recording the visitor's IP address, operating system type characteristics, for further analysis of customer groups to provide a basis.
2. Fill in the message HTML file:
Write.htm
This document constructs the most basic interface of the message, defines a form containing the basic filling items, such as name, email, message content, and submits the error check and warehousing processing by the savemsg.php program. 3
. Error checking and warehousing processing savemsg.php
{Sdb = mysql_connect (′localhost′,′username′,′password′);//Connect to the database, and note that the username and password are replaced with their own username and password to match the actual situation
mysql_select_db (′test′); Select the database where the Guesbook table is located, this is the test library
Squery=″insert into Guestbook (name, email,msgdate,msg) VALUES (′sname′,′semail′, now (), ′smsg′) ″; To construct an SQL statement that inserts data
mysql_query (Squery, Sdb); Perform insert data operation}?>
We may have noticed that in the SQL statement we used the MySQL now () function to ' Yyyy-mm-dd hh:mm: The SS ' form returns the current datetime and is stored directly in the DateTime field (in fact, the default value of the Msgdate field can be set to now () when the field is defined, so that we don't have to deal with the program separately), and the other Curdate () YYYY-MM-DD ' format returns today's date, which can be saved directly to the Date field, and Curtime () returns the current time in ' HH:MM:SS ' format, which can be saved directly to the Duration field.
4. View Message view.php
     
     
mysql_select_db (′test′); Select Database
Squery=″select * from Guestbook″; Constructing query statements
Sresult=mysql_query (Squery, Sdb); Executing query statements
echo′ Name email message time message content
′;
To construct a table header
while (Srow = Mysql_fetch_array (Sresult)) {//Circular output table
echo′′. srow[″name″].′′;
echo′′. srow[″email″].′′;
echo′′. srow[″msgdate″].′′;
echo′′. srow[″msg″].′
′; }
Mysql_free_result (sresult);/Free Resources
Mysql_close (SDB);//Close Database
echo′′; ?>
     
     
5.   Admin message book, which lists all the message entry profiles and provides a checkbox for each entry for deletion. addmin.php
Here, we have built a fill, save, browse, management (mainly delete operations) and other functions of the message book. It should be said that the program achieves our intended purpose. However, a message is really put into practice, must consider a number of special circumstances, and has a good man-machine interface, and a certain fault-tolerant, error-correcting. Compare the mature message on the network this program, we still need a lot of work, these will be in the next period "message board production advanced Skills" in the introduction, it is here, goodbye!

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.