数据表: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 ; 
config.php<?php 
$conn = @mysql_connect("localhost","root","") or die("数据库连接出错!"); 
mysql_select_db("gb",$conn); 
mysql_query("set names 'GBK'"); 
?> 
add.php<?php 
include("config.php"); 
if($_POST['submit']){ 
$sql="insert into message (id,user,title,content,lastdate) values ('','$_POST[user]','$_POST[title]','$_POST[content]',now())"; 
mysql_query($sql); 
echo "成功"; 

?> 
<form action="add.php" method="post"> 
用户:<input type="text" name="user" /><br> 
标题:<input type="text" name="title" /><br /> 
内容:<textarea name="content"></textarea><br /> 
<input type="submit" name="submit" value="提交" /> 
</form> 
view.php<?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)){ 
?> 
<tr bgcolor="#eff3ff"> 
<td>标题:<?php echo $row[title];?> 用户:<?php echo $row[user];?></td> 
</tr> 
<tr bgColor="#ffffff"> 
<td>内容:<?php echo $row[content];?></td> 
</tr> 
<?php 

?> 
</table> 

解决方案 »

  1.   

    表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=utf8 AUTO_INCREMENT=1 ;
    config.php<?php 
    ini_set('display_errors','off');
    $conn = @mysql_connect("数据库ip","帐号","密码") or die("数据库连接出错!"); 
    mysql_select_db("数据库名",$conn); 
    ?> 
    add.php<?php 
    include("config.php"); 
    if($_POST['submit']){ 
    $sql="insert into message (user,title,content,lastdate) values ('$_POST[user]','$_POST[title]','$_POST[content]',now())"; 
    mysql_query($sql); 
    echo "成功"; 

    ?> 
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <form action="add.php" method="post"> 
    用户:<input type="text" name="user" /><br> 
    标题:<input type="text" name="title" /><br /> 
    内容:<textarea name="content"></textarea><br /> 
    <input type="submit" name="submit" value="提交" /> 
    </form> 
    view.php<?php 
    include("config.php"); 
    ?> 
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <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)){ 
    ?> 
    <tr bgcolor="#eff3ff"> 
    <td>标题:<?php echo $row[title];?> 用户:<?php echo $row[user];?></td> 
    </tr> 
    <tr bgColor="#ffffff"> 
    <td>内容:<?php echo $row[content];?></td> 
    </tr> 
    <?php 

    ?> 
    </table>