在oso网站支持PHP和Mysql给我们提供展现web的世界!现在我就以oso里提供的mysql空间来编个留言板!
当然你现在得有mysql的空间,首先在phpMyAdmin里建个表,表名为liuyan,
表的字段依次为:
字段 类型 属性 Null 额外
bianhao int(11) 否 auto_increment
mingzi varchar(10) 否
riqi datetime 否
zhuti varchar(100) 否
neirong longtext 是
留言板的主窗口为文件:gotoliuyan.html
<!--留言主窗口--->
<html>
<body>
<form action="liuyan.php" method="post" name="lin">
<br>
<center>
<font color=green><b>留言板</b></font>
</center>
<hr>
<center>
<font color=blue><b>您的名字:</b></font><input type=text name="ming" ><br>
<font color=blue><b>留言主题:</b></font><input type=text name="zhuti" ><br>
</center>
<font color=blue><b>留言内容:</b></font><br>
<hr>
<center>
<textarea name="msgbody" cols=80 rows=8>
</textarea><br>
<input type=submit value="确定">
<hr>
</form>
<br>
<br>
<a href="chakanliuyan.php">查看留言</a>
</center>
</body>
</html>
当然人家留言提交后要保存起来的,提交到liuyan.php来保存的!
<!--保存留言-->
<html>
<body>
<center>
<font color=green><b>留言板</b></font>
</center>
<hr>
<?PHP
echo "<font color=blue><b>信息</b></font><br>";
echo "<font color=blue><b>您的名字:</b></font>$ming<br>";
echo "<font color=blue><b>留言主题:</b></font>$zhuti<br>";
echo "<font color=blue><b>您的留言的内容:</b></font>$msgbody<br>";
echo "<hr>";
$linkmysql=mysql_connect("localhost","yourname","password");
mysql_select_db("yourname",$linkmysql);
$str="insert into liuyan(bianhao,mingzi,zhuti,riqi,neirong) values('','".$ming."'".$zhuti."',NOW(),'".$msgbody."')";
mysql_query($str,$linkmysql);
mysql_close($linkmysql);
?>
<font color=green><b>流言成功!</b></font>
<hr>
<center>
<a href="gotoliuyan.html">还回</a><br><br>
<a href="chakanliuyan.php">查看留言</a>
</center>
</body>
</html>
留言后,当然要人家查看的!查看留言的程序是chankanliuyan.php
<!--查看留言-->
<html>
<body>
<center>
<br>
<font color=green><b>查看留言</b></font>
</center>
<hr>
<table border="1">
<tr>
<td align=center><font color=blue><b>编号</b></font>
<td align=center><font color=blue><b>名字</b></font>
<td align=center><font color=blue><b>主题</b></font>
<td align=center><font color=blue><b>日期</b></font>
<td align=center><font color=blue><b>留言</b></font>
</tr>
<?php
$linkmysql=mysql_connect("localhost","yourname","password");
mysql_select_db("yourname",$linkmysql);
$str="select bianhao,mingzi,zhuti,riqi,neirong from liuyan";
$res=mysql_query($str,$linkmysql);
while(list($bianhao,$mingzi,zhuti,$riqi,$neirong)=mysql_fetch_row($res)){
echo "<tr>";
$i=strlen($bianhao);
for($j=0;$j<4-$i;$j++)$bianhao="0".$bianhao;
echo "<td width=40><font color=green>$bianhao</font>";
echo "<td width=50><font color=green>$mingzi</font>";
echo "<td width=50><font color=green>$zhuti</font>";
echo "<td width=160><font color=green>$riqi</font>";
echo "<td><font color=green>$neirong</font>";
echo "</tr>";
}
mysql_close($linkmysql);
?>
</table>
<hr>
<a href="gotoliuyan.html">还回</a>
</body>
</html>
|