Config. php
Copy codeThe Code is as follows:
<? Php
$ Conn = @ mysql_connect ("localhost", "root", "") or die ("database connection error! ");
Mysql_select_db ("gb", $ conn );
Mysql_query ("set names 'gbk '");
?>
Add. php
Copy codeThe Code is as follows:
<? Php
Include ("config. php ");
If ($ _ POST ['submit ']) {
// In this case, the lastdate field in the message is not written, causing data insertion to fail. It takes a long time to locate the error.
$ SQL = "insert into message (id, user, title, content, lastdate) values ('', '$ _ POST [user]', '$ _ POST [title]', '$ _ POST [content]', now ())";
Mysql_query ($ SQL );
Echo "successful ";
}
?>
<Form action = "add. php" method = "post">
User: <input type = "text" name = "user"/> <br>
Title: <input type = "text" name = "title"/> <br/>
Content: <textarea name = "content"> </textarea> <br/>
<Input type = "submit" name = "submit" value = "submit"/>
</Form>
View. php
Copy codeThe Code is as follows:
<? Php
Include ("config. php ");
?>
<Table width = 500 border = "0" align = "center" cellpadding = "5" cellspacing = "1" bgcolor = "# add3ef">
<? Php
$ SQL = "select * from message order by id desc ";
$ Query = mysql_query ($ SQL );
While ($ row = mysql_fetch_array ($ query )){
?>
// NND. In the default wampserver environment, I use <? = $ Row [title]?> This syntax means that no content can be read. You must use this method. Depressed. It took a long time to figure it out.
<Tr bgcolor = "# eff3ff">
<Td> title: <? Php echo $ row [title];?> User: <? Php echo $ row [user];?> </Td>
</Tr>
<Tr bgColor = "# ffffff">
<Td> content: <? Php echo $ row [content];?> </Td>
</Tr>
<? Php
}
?>
</Table>
Then there is a database SQL.
Copy codeThe 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;