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:
- 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 database connection code is relatively fixed. first create a new conn. php file and enter the following code:
The instance 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;
- ?>
Write the add. php file on the posting page and enter the following code:
The instance 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
-
Write the message list file to create the file list. php, and enter the following code:
The instance code is as follows:
- Include ("conn. php ");
- ?>
- $ SQL = "select * from message ";
- $ Query = mysql_query ($ SQL );
- While ($ row = mysql_fetch_array ($ query) {?>
- Title: User:
- Published content:
-
-
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.