Php message board creation tutorial

Source: Internet
Author: User
This article provides php beginners with an article from database creation to the final read/write message board process. For more information, see. This is just an entry-level php Tutorial. if you want to use it for the network, please do some security and SQL

This article provides php beginners with an article from database creation to the final process of reading and writing message boards. For more information, see.

The code for creating a data table instance is as follows:

  1. Create table 'message '(
  2. 'Id' tinyint (1) not null auto_increment,
  3. 'User' varchar (25) not null,
  4. 'Title' varchar (50) not null,
  5. 'Content' tinytext not null,
  6. 'Lastdate' date not null,
  7. Primary key ('id ')
  8. ) ENGINE = InnoDB default charset = gbk AUTO_INCREMENT = 1;

Database Connection file database connection code is relatively fixed. first create a new conn. php file and enter the following code:

The instance code is as follows:

  1. $ Conn = mysql_connect ("localhost", "root", "") or die ("database link error ");
  2. Mysql_select_db ("test", $ conn );
  3. Mysql_query ("set names 'gbk'"); // use GBK Chinese encoding;
  4. ?>

Write the add. php file on the posting page and enter the following code:

The instance code is as follows:

  1. Include ("conn. php ");
  2. If ($ _ POST ['submit ']) {
  3. $ SQL = "insert into message (id, user, title, content, lastdate) values (", '$ _ POST [user]', '$ _ POST [biaoti]', '$ _ POST [content]', now ())";
  4. Mysql_query ($ SQL );
  5. Echo "published successfully! ";
  6. }
  7. ?>
  8.  
  9.  
  10. Post message box
  11.  

Write the message list file to create the file list. php, and enter the following code:

The instance code is as follows:

  1. Include ("conn. php ");
  2. ?>
  3. $ SQL = "select * from message ";
  4. $ Query = mysql_query ($ SQL );
  5. While ($ row = mysql_fetch_array ($ query) {?>
  6. Title: User:  
  7. Published content:  
  8.  
  9.  

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

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.