The message board can be said to be a small WEB application that all php beginners will practice. below I will share an example of a php message board I have written with you.
The message board can be said to be a small WEB application that all php beginners will practice. below I will share an example of a php message board I wrote with you, for more information, see references.
1. create a folder named "msgboard" under the root directory of your PHP. create a "msglist. php" file under "msgboard". you can directly import the data table structure.
The instance code is as follows:
- Create table 'msgboard '(
- 'Id' int (10) not null AUTO_INCREMENT,
- 'Username' varchar (50) character set latin1 not null,
- 'Sex' tinyint (1) not null default '1 ',
- 'MSG 'text character set latin1 not null,
- Primary key ('id ')
- ) ENGINE = MyISAM AUTO_INCREMENT = 1 default charset = utf8;
Msglist. php file, including adding, deleting, and modifying messages
The instance code is as follows:
-
-
-
- My message board
-
-
-
- $ Username = isset ($ _ REQUEST ['username'])? $ _ REQUEST ['username']: ''; // name
- $ Sex = isset ($ _ REQUEST ['Sex '])? Intval ($ _ REQUEST ['sex']): 1; // gender
- $ Msg = isset ($ _ REQUEST ['MSG '])? $ _ REQUEST ['MSG ']: ''; // Leave a message
-
-
- Mysql_connect ("127.0.0.1", "root", "lzy"); // link
- Mysql_select_db ("test"); // select a database
-
- If (! Emptyempty ($ username )&&! Emptyempty ($ msg ))
- {
- Mysql_query ("insert into msgboard (username, sex, msg) VALUES ('$ username',' $ sex', '$ msg ')");
- }
- Else
- {
- Echo "incorrect input
";
- }
-
- $ Source = mysql_query ("SELECT * FROM msgboard order by id DESC ");
- $ Result = array ();
-
- ?>
-
-
- Name
- Gender
- Message content
-
-
- While ($ row = mysql_fetch_array ($ source ))
- {
- Echo''. $ Row ['username'].'';
- Echo''. ($ Row ['sex'] = 1? 'Male': 'Female ').'';
- Echo''. $ Row ['MSG'].'';
- }
- ?>
-
-
-
-
-