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 ;
建立文件show.php 用来进行展示
<meta charset="utf-8">
<table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef">
<?php
include("link.php");
$sql="select * from message ";
$query=mysql_query($sql);
while ($row=mysql_fetch_array($query)){
?>
<tr bgcolor="#eff3ff">
<td>标题:<?=$row['title']?> 用户:<?=$row['user']?></td>
</tr>
<tr bgColor="#ffffff">
<td>内容:<?=$row['content']?></td>
</tr>
<?php
}
?>
</table>
建立add.php 发表留言,添加留言
<?php
include("link.php");
?>
<meta charset="utf-8">
<form action="add.php" method="post"><br>
用户:<input type="text" size="10" name="user"/><br>
标题: <input type="text" name="title" /><br>
内容:<textarea name="content"></textarea><br><br/>
<input type="submit" name="submit" value="发表留言"/>
</form>
<?php
if($_POST['submit']){
$sql="insert into message (id,user,title,content,lastdate)".
"value('','$_POST["user"]','$_POST["title"]','$_POST["content"]',now())";
mysql_query($sql);
echo "发表成功";
}
?>
建立link.php 用来进行数据库的连接
<?php
$conn =@ mysql_connect("localhost","root","root") or die(数据库链接错误);
mysql_select_db ("bbs",$conn);
mysql_query("set names GBK");
?>