特点:
支持oicq头像,自动分页,显示留言人ip,email合法性验证,方便安全的留言管理,
没有复杂函数,初学者也很容易看懂。
程序示例:http://medguider.51.net/notebook/
完整程序下载(包括图片)http://medguider.51.net/download/notebook.zip
程序清单:
config.php 配置文件 mysql.txt 数据库文件 index.php 显示留言主程序 addnote.php 添加留言 delnote.php 删除留言
mysql.txt
create table notebook (name char(6),email varchar(35),time char(30),face char(2),ip varchar(16),title varchar(255),nnote text);
//留言簿 name 姓名 email time 时间 face 头像 ip title 标题 nnote 内容
config.php
1
2//这里改为自己的数据库用户名与密码
3$db = mysql_connect("localhost", "root");
4mysql_select_db("test",$db);
5//这里改为自己的管理用户名和密码
6$username="demo";
7$password="demo";
index.php
1<html>
2<head>
3<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
4<title>留言簿</title>
5<style type="text/css">
6<!--
7.blue9 { font-size: 9pt; color: #0099FF; text-decoration: none}
8.black9 { font-size: 9pt; text-decoration: none}
9.purple10 { font-size: 10pt; color: #9900FF; text-decoration: none}
10.white12 { font-size: 12pt; color: #FFFFFF; text-decoration: none}
11a:visited { color: #FFFFFF}
12a:link { color: #FFFFFF}
13\-->
14</style>
15</head>
16<body bgcolor="#FFFFFF">
include ("config.php");
$result = mysql_query("SELECT * FROM notebook ",$db);
$row=mysql_num_rows($result);//查看查询结果有多少行
$max=$row; //帖子总数
//设每页显示10篇,可自行设定,$p总页数,$page第几页,$low 从第几行开始读,$x 读取几行
if (!$page){ $page=1;}//$page默认值为1
$p=ceil($max/10);//页数为$max/10的最大整数
$low=10*($page-1);
if($page==$p&&($max%10)<>0){$x=($max%10);} else {$x=10;}//如果是最后一页,且不是10的整倍数,读取$max除以10的余数,否则取10
if($max==0){$x=0;}//如果没有帖子,$x取0
$result = mysql_query("select * from notebook ORDER BY time DESC limit $low,$x",$db);//按照帖子的时间降序查询
1<table border="0" cellpadding="0" cellspacing="0" height="61" width="98%">
2<tr>
3<td height="62" width="34%"><a href="http://www.medguider.com"><img alt="医学导航网" border="0" height="60" src="image/logo.gif" width="243"/></a></td>
4<td height="62" width="66%">
5<div align="center"><img height="60" src="image/note.gif" width="410"/><img height="60" src="image/y1.gif" width="60"/></div>
6</td>
7</tr>
8</table>
9<table align="center" border="1" bordercolordark="#FFFFFF" bordercolorlight="#003399" cellpadding="0" cellspacing="0" height="253" width="95%">
10<tr>
11<td height="250">
12<div align="center"></div>
13<table bgcolor="#3366FF" border="0" cellpadding="0" cellspacing="0" height="32" width="95%">
14<tr>
15<td class="white12" height="23" width="26%"><a class="white12" href="../index.php">首页</a>
16> 留言簿</td>
17<td class="white12" height="23" width="48%">
echo "帖子总数: ",$max," 第";
for ($n=1;$n<=$p;$n++){
echo "<a href="index.php?page=$n">$n</a> ";
}
echo "页";
1</td>
2<td height="23" width="15%"><a href="addnote.php"><img border="0" height="21" src="image/newthread.gif" width="91"/></a></td>
3<td height="23" width="11%"><a href="delnote.php"><span class="white12">留言管理</span></a></td>
4</tr>
5</table>
for ($i=0;$i<=($x-1);$i++) {
$name=mysql_result($result,$i,'name');
$email=mysql_result($result,$i,'email');
$face=mysql_result($result,$i,'face');
$face='image/face/icon'.$face; //用户头像
$time=mysql_result($result,$i,'time');
$ip=mysql_result($result,$i,'ip');
$title=mysql_result($result,$i,'title');
$nnote=mysql_result($result,$i,'nnote');
echo "<table border="0" bordercolor="#FFFFFF" cellpadding="0" cellspacing="0" height="107'" width="100%"> <tr bgcolor="#eeeeee">";
echo "<td bgcolor="#eeeeee" class="blue9" height="33" width="10%"> <img height="32" src="$face.gif" width="32"/></td>";
echo "<td bgcolor="#eeeeee" class="blue9" height="33" width="16%">留言人:$name</td>";
echo "<td bgcolor="#eeeeee" class="blue9" height="33" width="41%">发表于:$time</td>";
echo "<td bgcolor="#eeeeee" class="blue9" height="33" width="12%"><a href="mailto:$email"><img border="0" height="16" src="image/email.gif" width="16"/></a></td>";
echo "<td class="blue9" height="33" width="21%"><img height="15" src="image/ip.gif" width="13"/> $ip</td> </tr> <tr>";
echo "<td class="purple10" colspan="5" height="33">标题:$title</td> </tr>";
echo "<tr bgcolor="#ffffff"><td class="black9" colspan="5" height="37">留言内容:$nnote</td></tr></table>";
}
mysql_close($db);
1</td>
2</tr>
3</table>
4</body>
5</html>