config.php
Copy Code code 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 Code code as follows:
<?php
Include ("config.php");
if ($_post[' submit ']) {
Here, forget the message there is a field lastdate not write, resulting in the insertion of data is unsuccessful. It took a long time to find out the mistake.
$sql = "INSERT into message (id,user,title,content,lastdate) VALUES (', ' $_post[user] ', ' $_post[title] ', ' $_post[ Content] ', now () ';
mysql_query ($sql);
echo "Success";
}
?>
<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= "Submission" value= "submitted"/>
</form>
view.php
Copy Code code 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. I am in wampserver default environment, using <?= $row [title]?> This syntax, is not read content. This is the only kind of work you can do. Depressed. It was a long time before I figured 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 the SQL of the database.
Copy Code code as follows:
CREATE TABLE ' message ' (
' id ' tinyint (1) is not NULL auto_increment,
' user ' varchar NOT NULL,
' title ' varchar ' is not NULL,
' content ' is tinytext not null,
' lastdate ' date Not NULL,
PRIMARY KEY (' id ')
) Engine=innodb DEFAULT CHARSET=GBK auto_increment=1;