Php message board making tutorial _ PHP Tutorial

Source: Internet
Author: User
Php message board creation tutorial. This article provides php beginners with an article from database creation to the final read/write message board process. For more information, see. Create a data table this article will share with you the process from creating a database to reading and writing a message board. For more information, see.

Create a data table

The code is as follows:

Create table 'message '(

'Id' tinyint (1) not null auto_increment,

'User' varchar (25) not null,

'Title' varchar (50) not null,

'Content' tinytext not null,

'Lastdate' date not null,

Primary key ('id ')

) ENGINE = InnoDB default charset = gbk AUTO_INCREMENT = 1;

Database Connection file

The database connection code is relatively fixed. Create a new conn. php file and enter the following code:

The code is as follows:

$ Conn = mysql_connect ("localhost", "root", "") or die ("database link error ");

Mysql_select_db ("test", $ conn );

Mysql_query ("set names 'gbk'"); // use GBK Chinese encoding;

?>

Compile the posting page File
Create an add. php file and enter the following code:

The code is as follows:

Include ("conn. php ");

If ($ _ POST ['submit ']) {

$ SQL = "insert into message (id, user, title, content, lastdate) values (", '$ _ POST [user]', '$ _ POST [biaoti]', '$ _ POST [content]', now ())";

Mysql_query ($ SQL );

Echo "published successfully! ";

}

?>


Post message box


Compile the message list file
Create a file list. php and enter the following code:

The code is as follows:

Include ("conn. php ");

?>

$ Query = mysql_query ($ SQL );

While ($ row = mysql_fetch_array ($ query) {?>

$ SQL = "select * from message ";

Title: User:
Published content:

Note,This is just an entry-level php Tutorial. if you want to use it for the network, please do some security and SQL injection filtering. Otherwise, it will be very insecure.

Bytes. Create a data table...

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.