1. Create a folder named "msgboard" under the root directory of your PHP.
Create a "msglist. php" file under "msgboard"
Data table structure can be imported directly.
The code is as follows: |
Copy code |
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 code is as follows: |
Copy code |
<Html> <Head> <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"> <Title> My Message Board </title> </Head> <Body> <? Php $ 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 (! Empty ($ username )&&! Empty ($ msg )) { Mysql_query ("insert into msgboard (username, sex, msg) VALUES ('$ username',' $ sex', '$ msg ')"); } Else { Echo "incorrect input <br/> "; } $ Source = mysql_query ("SELECT * FROM msgboard order by id DESC "); $ Result = array (); ?> <Table border = "1" width = "1000"> <Tr align = "center"> & Lt; td width = "10%" & gt; Name & lt;/td & gt; <Td width = "10%"> Gender </td> <Td width = "80%"> Message Content </td> </Tr> <Tr> <? Php While ($ row = mysql_fetch_array ($ source )) { Echo '<td>'. $ row ['username']. '</td> '; Echo '<td>'. ($ row ['sex'] = 1? 'Male': 'Female ').' </td> '; Echo '<td>'. $ row ['MSG '].' </td> '; } ?> </Tr> </Table> <p/> <Form action = "msglist. php" method = "POST"> <Table width = "1000" align = "left"> <Tr> & Lt; td width = "100%" & gt; Name: <input type = "text" name = "username" value = "/> </Td> </Tr> <Tr> & Lt; td width = "100%" & gt; Gender: Male <input type = "radio" name = "sex" value = "1" checked = "checked"/> & nbsp; Female <input type = "radio" name = "sex" value = "0"/> </Td> </Tr> <Tr> & Lt; td width = "100%" & gt; Leave a message: <br/> <textarea name = "msg" rows = "5" cols = "100"> </textarea> </Td> </Tr> <Tr> & Lt; td width = "100%" & gt; <Input type = "submit" value = "submit"/> </Td> </Tr> </Table> </Form> </Body> </Html> |
A php message board instance Download: http://file.111cn.net/download/2013/06/08/msgboard.rar