15.3.3 留言簿留言簿可供用户留言、发布信息。留言簿的使用对象可分为一般用户及留言簿管理员两类,一般用户只能浏览及留言,管理员除了可以浏览及留言之外还可以删除、修改留言。以下将逐一介绍浏览、留言、管理员登陆验证、删除及修改留言5个功能。
留言簿数据库名为:Demo,它包括的数据库表有guestbook_admins(如表15.2所示),guestbook_users(如表15.3所示)及guestbook_messages(如表15.4所示)。表guestbook_admin及guestbook_users是管理员及用户的信息表,表guest_messages是留言信息表。数据库表结构如下:
表 15.2 guestbook_admins表结构列名
数据类型
长度
允许空
username
Char
20
√
Password
Char
20
√
表15.3 guestbook_users表结构列名
数据类型
长度
允许空
Username
Char
20
√
Password
Char
20
√
表15.4 guestbook_massages表结构列名
数据类型
长度
允许空
Id
bigint
8
Username
Char
20
√
Subject
Char
100
√
Content
Char
1000
√
[Date]
datetime
8
√
1.浏览
以下是浏览留言的界面。用户必须先在图15.22 的窗口中选择要浏览的留言,然后进入图15.23的窗口,进行浏览。可以看出 图15.22,图15.23与【例15.9】类似,所以可以引用【例15.9】的程序“sele_record.asp”与“list_sele_record.asp”实现浏览的功能。

图15.22 选择要浏览的留言

图15.23 显示留言内容
<sele_record_gue.asp源程序>
<% Option Explicit %>
<%
'建立一个到数据源的连接
Dim strDSN
Dim connDemo
strDSN="Provider=MSDASQL;DRIVER={SQL Server};SERVER=127.0.0.1;DATABASE=Demo;UID=chen;PWD=123"
Set connDemo = Server.CreateObject("ADODB.Connection")
connDemo.Open strDSN
'建立记录集,存放查询结果
Dim rsMessages
Dim strSqlSelectMessages
Set rsMessages = Server.CreateObject("ADODB.Recordset")
strSqlSelectMessages="SELECT * FROM guestbook_messages ORDER BY date"
rsMessages.Open strSqlSelectMessages,connDemo,3,3
%>
<!--结果输出(以供选择)-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>功能模块“留言板”</title>
<SCRIPT>
function OpenWindows(url){
var newwin=window.open(url,"_blank","toolbar=no,location=no,directories=no,status=no,"+
"menubar=no,scrollbars=yes,resizable=yes,"+
"top=50,left=120,width=600,height=400");
return false;
}
</SCRIPT>
</head>
<body bgcolor="#C0C0C0">
<table width="550" height="18">
<tr>
<td width="326" height="15">
<font face="华文行楷" size="8">留言板&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</font>
</td>
<td width="210" height="17">
<a href="select_record_gue.asp">
首页</a>&nbsp;&nbsp; <a href="add_record_gue.htm">留言</a>&nbsp;&nbsp;
<a href="logon.asp">管理</a>
</td>
</tr>
<tr>
<td colspan="2" width="542" height="1">
<hr>
</td>
</tr>
</table>
<%
If Not rsMessages.Eof Then
%>
<table border="1" cellpadding="8" cellspacing="0" width="613" height="41">
<tr>
<th width="351" height="16" >发言主题</th>
<th width="62" height="16" >发言者</th>
<th width="151" height="16" >发言时间</th>
</tr>

<%
Do While Not rsMessages.Eof
%>
<tr>

<td width="368" height="1">
<a href="list_sele_record_gue.asp?id=<% =rsMessages("id") %>" onClick='return OpenWindows(this.href);'><font face="宋体" size="2"><% =rsMessages("subject") %></font></a>
</td>
<td width="94" height="1"><font face="宋体" size="2"><% =rsMessages("username") %></font></td>
<td width="128" height="1"><font face="宋体" size="2"><% =rsMessages("date") %></font></td>
<%
rsMessages.MoveNext
Loop
End If
%>
</table>
</body>
</html>
<list_sele_record_gue.asp源程序>
<% Option Explicit %>
<%
'接受表单输入的数据
Dim id
id=Request.QueryString("id")
'建立一个到数据源的连接
Dim strDSN
Dim connDemo
strDSN="Provider=MSDASQL;DRIVER={SQL Server};SERVER=127.0.0.1;DATABASE=Demo;UID=chen;PWD=123"
Set connDemo = Server.CreateObject("ADODB.Connection")
connDemo.Open strDSN
'建立记录集,存放查询结果
Dim rsMessages
Dim strSqlSelectMessages
Set rsMessages = Server.CreateObject("ADODB.Recordset")
strSqlSelectMessages="SELECT * FROM guestbook_messages WHERE id=" & id & ""
rsMessages.Open strSqlSelectMessages,connDemo

%>
<!--显示结果-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>功能模块“留言板”</title>
</head>
<body bgcolor="#C0C0C0">
<table width="550" height="23">
<tr>
<td width="326" height="19">
<font face="华文行楷" size="8">留言板&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</font>
</td>
<td width="210" height="19">
<a href="select_record_gue.asp">
首页</a>&nbsp;&nbsp; <a href="add_record_gue.htm"> 留言</a>&nbsp;&nbsp;
<a href="logon.asp">管理</a>
</td>
</tr>
<tr>
<td colspan="2" width="542" height="1">
<hr>
</td>
</tr>
</table>
&nbsp;&nbsp;
<table border="1" height="120" cellspacing="1" width="616">
<tr>
<td height="19" width="354">
主题:<% =rsMessages("subject") %>
</td>
<td height="19" width="123">
作者:<% =rsMessages("username") %>
</td>
<td height="19" width="123">
日期:<% =rsMessages("date") %>
</td>
</tr>
<tr>
<td colspan="3" height="16" width="606">内容:</td>
</tr>
<tr>
<td colspan="3" height="67" width="606">
<% =rsMessages("content") %>
</td>
</tr>
</table>
</body>
</html>
2.留言用户可进入如图15.24所示的窗口,输入留言内容。输入留言实际上就是在guestbook-messages表中“添加记录”

图15.24 留言可以看出 图15.24与【例15.5】“添加记录”类似,所以可以引用【例15.5】的程序“add_record.htm”与“add_record.asp”。
<add_record_gue.htm源程序>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>功能模块“留言板”</title>
</head>
<body bgcolor="#C0C0C0">
<table width="550" height="23">
<tr>
<td width="326" height="19">
<font face="华文行楷" size="8">留言板&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</font>
</td>
<td width="210" height="19">
<a href="select_record_gue.asp">
首页</a>&nbsp;&nbsp; <a href="add_record_gue.htm"> 留言</a>&nbsp;&nbsp;
<a href="logon.asp">管理</a>
</td>
</tr>
<tr>
<td colspan="2" width="542" height="1">
<hr>
</td>
</tr>
</table>
&nbsp;&nbsp;&nbsp;&nbsp;
<form method="post" action="add_record_gue.asp">
<table border="1" height="26">
<tr>
<td height="16" colspan="2">
<p align="center">请留言</td>
</tr>
<tr>
<td height="32">发言主题:</td>
<td height="32"><input type="text" name="txtSubject" size="40"/><font face="宋体" size="2">*(标题限制 <b>40</b>
个字符以内)</font></td>
</tr>
<tr>
<td height="36">发言者:</td>
<td height="36"><input type="text" name="txtUserName"/><font face="宋体" size="2">*(名字限制 <b>10</b>
个字符以内)</font></td>
</tr>
<tr>
<td height="1">密 码(可选):</td>
<td height="1">
<input type="password" name="pwdPassword"/><font face="宋体" size="2">(填写密码成为保留用户,名字将被保护)</font>
</td>
</tr>
<tr>
<td width="100%" height="1" colspan="2">发言内容, </td>
</tr>
<tr>
<td width="100%" height="2" colspan="2"><textarea name="txtContent" rows="12" cols="83"></textarea>
<p align="center"><input type="submit" value="留言"/>&nbsp;&nbsp;&nbsp;
<input type="reset"/></p>
</td>
</tr>
</table>
<p style="line-height,100%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p>
</form>
</body>
</html>
<add_record_gue.asp源程序>
<% Option Explicit %>
<%
'建立一个到数据源的连接
Dim strDSN
Dim connDemo
strDSN="Provider=MSDASQL;DRIVER={SQL Server};SERVER=127.0.0.1;DATABASE=Demo;UID=chen;PWD=123"
Set connDemo = Server.CreateObject("ADODB.Connection")
connDemo.Open strDSN
'建立记录集,对用户进行操作
Dim rsUsers
Dim strSqlSelectUsers
Dim userName
Dim password

userName=Request.Form("txtUserName")
password=Request.Form("pwdPassword")

Set rsUsers = Server.CreateObject("ADODB.Recordset")
strSqlSelectUsers="SELECT * FROM guestbook_users WHERE username='"+userName+"'"
rsUsers.Open strSqlSelectUsers,connDemo,1,3

'判断用户是否存在
If Not rsUsers.Eof Then
'判断密码是否正确
If password<>trim(rsUsers("password")) Then
Response.Write("密码错误")
Response.end
End If
Else
'判断是否输入了密码,如输入了密码,则新建立一个用户帐号
If password<>"" Then
'接受表单输入数据,写入数据库表
rsUsers.AddNew
rsUsers("username")=userName
rsUsers("password")=password
rsUsers.Update
rsUsers.Close
set rsUsers=Nothing
End if
End if
'建立记录集,新建发言
Dim rsMessages
Dim strSqlSelectMessages
Set rsMessages = Server.CreateObject("ADODB.Recordset")
strSqlSelectMessages="SELECT * FROM guestbook_messages"
rsMessages.Open strSqlSelectMessages,connDemo,1,3
'接受表单输入数据,写入数据库表
rsMessages.AddNew
rsMessages("username")=Request.Form("txtUserName")
'rsMessages("password")=Request.Form("txtPassword")
rsMessages("date")=Now()
rsMessages("subject")=Request.Form("txtSubject")
rsMessages("content")=Request.Form("txtContent")
rsMessages.Update
rsMessages.Close
set rsMessages=Nothing
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>功能模块“留言板”</title>
</head>
<body bgcolor="#C0C0C0">
<table width="550" height="23">
<tr>
<td width="326" height="19">
<font face="华文行楷" size="8">留言板&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</font>
</td>
<td width="210" height="19">
<a href="select_record_gue.asp">
首页</a>&nbsp;&nbsp; <a href="add_record_gue.htm"> 留言</a>&nbsp;&nbsp;
<a href="logon.asp">管理</a>
</td>
</tr>
<tr>
<td colspan="2" width="542" height="1">
<hr>
</td>
</tr>
</table>
&nbsp;&nbsp;&nbsp;&nbsp;
<p>
留言已发布,点击<a href="select_record_gue.asp">返回</a>
</body>
</html>
3.管理员登陆验证管理员必须通过登陆验证才能进入管理员的窗口进行操作,在guestbook_admin数据库表中可以看到管理员的ID为“admin”,密码为“123”。
管理员登陆验证的过程即查询guestbook_admin数据库表的过程,如果查到username及passwoed与输入的匹配,则通过登录检验,访问者就可以进入管理系统,所以,管理员登录过程实际上就是“查询记录”过程。可用【例15.4】的“查询记录”基础模块2.1,只要把在query.asp的“结果输出”部分改成登录成功后要进入的网页,即删去“结果输出”部分,改为:<%response.redirect"登录成功后可进入的网页名.htm"%>。登陆验证包括“logon.asp”“authenticate.asp”两个程序.
<logon.asp源程序>
<%
'判断是否已登录
If Session("username")="admin" Then
Response.Redirect("sele_dele_record_gue.asp")
End if
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>基础模块“查询记录”之“输入查询串”</title>
</head>
<body bgcolor="#C0C0C0">
<table width="550" height="23">
<tr>
<td width="326" height="19">
<font face="华文行楷" size="8">留言板&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</font>
</td>
<td width="210" height="19">
<a href="select_record_gue.asp">
首页</a>&nbsp;&nbsp; <a href="add_record_gue.htm"> 留言</a>&nbsp;&nbsp;
<a href="logon.asp">管理</a>
</td>
</tr>
<tr>
<td colspan="2" width="542" height="1">
<hr>
</td>
</tr>
</table>
&nbsp;&nbsp;&nbsp;&nbsp;
<form method="POST" action="authenticate.asp">
<p>
<font face="华文行楷" size="6">请输入管理员帐号和密码</font>
</p>
<p>
用户名:<input type="text" name="txtUserName" size="20">
</p>
<p>
密&nbsp; 码:<input type="password" name="pwdPassword" size="20"> 
</p>
<p>
<input type="submit" value="登录" ><input type="reset" value="全部重填">
</p>
</form>
</body>
</html>
<authenticate.asp源程序>
<% Option Explicit %>
<%
'接受表单输入的数据
Dim userName,password
userName=Trim(Request.Form("txtUserName"))
password=Trim(Request.Form("pwdPassword"))
'建立一个到数据源的连接
Dim strDSN
Dim connDemo
strDSN="Provider=MSDASQL;DRIVER={SQL Server};SERVER=127.0.0.1;DATABASE=Demo;UID=chen;PWD=123"
Set connDemo = Server.CreateObject("ADODB.Connection")
connDemo.Open strDSN
'建立记录集,存放查询结果
Dim rsAdmins
Dim strSqlSelectAdmins
Set rsAdmins = Server.CreateObject("ADODB.Recordset")
strSqlSelectAdmins="SELECT * FROM guestbook_admins WHERE username='"+userName+"' And password='"+password+"'"
rsAdmins.Open strSqlSelectAdmins,connDemo
If Not rsAdmins.Eof then
Session("username")=userName
Response.Redirect("sele_dele_record_gue.asp")
End If
%>
<!--结果输出-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>功能模块“留言板”</title>
</head>
<body bgcolor="#C0C0C0">
<table width="550" height="23">
<tr>
<td width="326" height="19">
<font face="华文行楷" size="8">留言板&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</font>
</td>
<td width="210" height="19">
<a href="select_record_gue.asp">
首页</a>&nbsp;&nbsp; <a href="add_record_gue.htm"> 留言</a>&nbsp;&nbsp;
<a href="logon.asp">管理</a>
</td>
</tr>
<tr>
<td colspan="2" width="542" height="1">
<hr>
</td>
</tr>
</table>
用户名或密码错误!&nbsp;&nbsp;&nbsp;&nbsp;
</body>
</html>
程序“logout.asp”的作用是退出管理系统。
<logout.asp源程序>
<%
Session("username")=""
Response.Redirect("select_record_gue.asp")
%>
4.删除留言管理员进入管理系统后可以删除留言,其工作过程实际上是对表guestbook_messages实行“删除记录”的操作,所以,可以引用【例15.6】“删除记录”的模块。
<sele_dele_record_gue.asp源程序>
<% Option Explicit %>
<%
'判断是否已登录
If Session("username")<>"admin" Then
Response.Redirect("logon.asp")
End if

'建立一个到数据源的连接
Dim strDSN
Dim connDemo
strDSN="Provider=MSDASQL;DRIVER={SQL Server};SERVER=127.0.0.1;DATABASE=Demo;UID=chen;PWD=123"
Set connDemo = Server.CreateObject("ADODB.Connection")
connDemo.Open strDSN
'建立记录集,存放查询结果
Dim rsMessages
Dim strSqlSelectMessages
Set rsMessages = Server.CreateObject("ADODB.Recordset")
strSqlSelectMessages="SELECT * FROM guestbook_messages"
rsMessages.Open strSqlSelectMessages,connDemo
%>

<!--结果输出,以供选择-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>功能模块“留言板”</title>
</head>
<body bgcolor="#C0C0C0">
<table width="617" height="23">
<tr>
<td width="326" height="19">
<font face="华文行楷" size="8">留言板&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</font>
</td>
<td width="277" height="19">
<a href="select_record_gue.asp">
首页</a>&nbsp;&nbsp; <a href="add_record_gue.htm"> 留言</a>&nbsp;&nbsp;
<a href="logon.asp">删除</a>&nbsp;&nbsp;<a href="sele_modi_record_gue.asp"> 修改</a>&nbsp;&nbsp; <a href="logout.asp">退出</a>
</td>
</tr>
<tr>
<td colspan="2" width="609" height="1">
<hr>
</td>
</tr>
</table>
&nbsp;&nbsp;&nbsp;&nbsp;
<h3>请选择要删除的留言:</h3>
<%
If Not rsMessages.Eof Then
%>
<form method="post" action="delete_record_gue.asp">
<table border="1" cellpadding="8" cellspacing="0" width="609">
<tr>
<th width="313" >发言主题</th>
<th width="60" >发言者</th>
<th width="172" >发言时间</th>
<th width="18"></th>
</tr>

<%
Dim idCollection
Do While Not rsMessages.Eof

'将用户所选中的所有记录的id号存放在idCollection变量中,用","作为分隔符
idCollection=idCollection & rsMessages("id") & ","
%>
<tr>
<td width="313"><% =rsMessages("subject") %></td>
<td width="60"><% =rsMessages("username") %></td>
<td width="172"><% =rsMessages("date") %></td>
<td width="18">
<!--在每条记录后添加一个检查框,供用户选定记录-->
<input name="chkNo<% =rsMessages("id") %>" type="checkbox">
</td>
</tr>
<%
rsMessages.MoveNext
Loop
End If

rsMessages.Close
Set rsMessages=Nothing

'将idCollection贮存在一个隐藏对象中,以传递给下一个页面
Response.Write("<input type='hidden' name='hidIdCollection' value=" & idCollection & ">")
%>

</table>
<input type="submit" value="删除留言">
</form>
</body>
</html>
<delete_record_gue.asp源程序>
<% Option Explicit %>
<%
'判断是否已登录
If Session("username")<>"admin" Then
Response.Redirect("logon.htm")
End if

'建立一个到数据源的连接
Dim strDSN
Dim connDemo
strDSN="Provider=MSDASQL;DRIVER={SQL Server};SERVER=127.0.0.1;DATABASE=Demo;UID=chen;PWD=123"
Set connDemo = Server.CreateObject("ADODB.Connection")
connDemo.Open strDSN

'删除记录
Dim idCollection,strLength,totalOfIds,i,id,strSqlDeleteUser

idCollection=request.form("hidIdCollection")
strLength=Len(idCollection)
idCollection=Left(idCollection,strLength-1)
idCollection=Split(idCollection,",")
totalOfIds=UBound(idCollection,1)

For i=0 to totalOfIds
id=Request.Form("chkNo" & idCollection(i))
If Not IsEmpty(id) Then
strSqlDeleteUser="DELETE FROM guestbook_messages WHERE id=" & Clng(idCollection(i))
connDemo.Execute strSqlDeleteUser
End If
Next

'建立记录集,存放查询结果
Dim rsMessages
Dim strSqlSelectMessages
Set rsMessages = Server.CreateObject("ADODB.Recordset")
strSqlSelectMessages="SELECT * FROM guestbook_messages"
rsMessages.Open strSqlSelectMessages,connDemo
%>
<!--结果输出-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>功能模块“留言板”</title>
</head>
<body bgcolor="#C0C0C0">
<table width="550" height="23">
<tr>
<td width="326" height="19">
<font face="华文行楷" size="8">留言板&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</font>
</td>
<td width="210" height="19">
<a href="select_record_gue.asp">
首页</a>&nbsp;&nbsp; <a href="add_record_gue.htm"> 留言</a>&nbsp;&nbsp;
<a href="sele_dele_record_gue.asp">删除</a> <a href="sele_modi_record_gue.asp"> 修改</a> <a href="logout.asp">退出</a>
</td>
</tr>
<tr>
<td colspan="2" width="542" height="1">
<hr>
</td>
</tr>
</table>
&nbsp;&nbsp;&nbsp;&nbsp;
<h3>您所选择的留言已删除。数据库中剩余的留言为:</h3>

<%
If Not rsMessages.Eof Then
%>
<table border="1" cellpadding="8" cellspacing="0" width="589">
<tr>
<th width="323" >发言主题</th>
<th width="95" >发言者</th>
<th width="163" >发言时间</th>
</tr>
<%
Do While Not rsMessages.Eof
%>
<tr>
<td width="323"><% =rsMessages("subject") %></td>
<td width="95"><% =rsMessages("username") %></td>
<td width="163"><% =rsMessages("date") %></td>
</tr>
<%
rsMessages.MoveNext
Loop
End If
%>
</table>
</body>
</html>
5.修改留言管理员进入管理系统后可以修改留言,其工作过程实际上是对表guestbook_
messages实行“修改记录”的操作,所以,可以引用【例15.7】“修改记录”的模块
<sele_modi_record_gue.asp源程序>
<% Option Explicit %>
<%
'判断是否已登录
If Session("username")<>"admin" Then
Response.Redirect("logon.htm")
End if
'建立一个到数据源的连接
Dim strDSN
Dim connDemo
strDSN="Provider=MSDASQL;DRIVER={SQL Server};SERVER=127.0.0.1;DATABASE=Demo;UID=chen;PWD=123"
Set connDemo = Server.CreateObject("ADODB.Connection")
connDemo.Open strDSN
'建立记录集,存放查询结果
Dim rsMessages
Dim strSqlSelectMessages
Set rsMessages = Server.CreateObject("ADODB.Recordset")
strSqlSelectMessages="SELECT * FROM guestbook_messages"
rsMessages.Open strSqlSelectMessages,connDemo,3,3
%>
<!--结果输出,以供选择-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>功能模块“留言板”</title>
</head>
<body bgcolor="#C0C0C0">
<table width="615" height="23">
<tr>
<td width="326" height="19">
<font face="华文行楷" size="8">留言板&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</font>
</td>
<td width="275" height="19">
<a href="select_record_gue.asp">
首页</a>&nbsp;&nbsp; <a href="add_record_gue.htm"> 留言</a>&nbsp;&nbsp;
<a href="logon.asp">删除</a>&nbsp;&nbsp;<a href="sele_modi_record_gue.asp"> 修改</a> &nbsp;&nbsp;<a href="logout.asp">退出</a>
</td>
</tr>
<tr>
<td colspan="2" width="607" height="1">
<hr>
</td>
</tr>
</table>
&nbsp;&nbsp;&nbsp;&nbsp;

<h3>请选择要修改的留言:</h3>

<%
If Not rsMessages.Eof Then
%>
<table border="1" cellpadding="8" cellspacing="0" width="612">
<tr>
<th width="382" >发言主题</th>
<th width="70" >发言者</th>
<th width="180" >发言时间</th>
<th width="17">* </th>
</tr>

<%
Do While Not rsMessages.Eof
%>
<tr>
<th width="382" ><% =rsMessages("subject") %></th>
<td width="70"><% =rsMessages("username") %></td>
<td width="180"><% =rsMessages("date") %></td>
<td width="17">
<a href="modify_record_gue.asp?id=<% =rsMessages("id") %>"><img src="../images/edit1.gif" width="16" height="17" border="0"></a>
</td>
<%
rsMessages.MoveNext
Loop
End If
%>
</table>
</body>
</html>
<modify_record_gue.asp源程序>
<% Option Explicit %>
<%
'判断是否已登录
If Session("username")<>"admin" Then
Response.Redirect("logon.htm")
End if
'从表单读出输入的数据
Dim id
Dim save
id=Request.QueryString("id")
save=Request.Form("btnSave")

'判断本页面的"保存"按钮是否被点击
If save="保存" Then

'建立一个到数据源的连接
Dim strDSN
Dim connDemo
strDSN="Provider=MSDASQL;DRIVER={SQL Server};SERVER=127.0.0.1;DATABASE=Demo;UID=chen;PWD=123"
Set connDemo = Server.CreateObject("ADODB.Connection")
connDemo.Open strDSN
'建立记录集,存放查询结果
Dim rsMessages
Dim strSqlSelectMessages
Set rsMessages = Server.CreateObject("ADODB.Recordset")
strSqlSelectMessages="SELECT * FROM guestbook_messages WHERE id='" & Request.Form("txtId") & "'"
response.write(strSqlSelectMessages)
rsMessages.Open strSqlSelectMessages,connDemo,1,3

response.write(Request.Form("txtSubject"))
'接受表单输入数据,修改记录
rsMessages("subject")=trim(Request.Form("txtSubject"))
rsMessages("content")=trim(Request.Form("txtContent"))
'rsMessages("username")=rsMessages("username")
'rsMessages("date")=Now()
'rsMessage("id")=rsMessages("id")
rsMessages.Update
rsMessages.Close
Set rsMessages=Nothing

'显示执行结果
Dim msg
msg="编辑成功!\n"
Response.Redirect("sele_modi_record_gue.asp")
Response.End
Else
'建立一个到数据源的连接
'Dim strDSN
'Dim connDemo
strDSN="Provider=MSDASQL;DRIVER={SQL Server};SERVER=127.0.0.1;DATABASE=Demo;UID=chen;PWD=123"
Set connDemo = Server.CreateObject("ADODB.Connection")
connDemo.Open strDSN
'建立记录集,存放查询结果
'Dim rsMessages
'Dim strSqlSelectMessages
Set rsMessages = Server.CreateObject("ADODB.Recordset")
strSqlSelectMessages="SELECT * FROM guestbook_messages WHERE id=" & id & ""
rsMessages.Open strSqlSelectMessages,connDemo,3,3
End If
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>基础模块“修改记录”之“修改记录”</title>
</head>
<body bgcolor="#C0C0C0">
<table width="615" height="23">
<tr>
<td width="326" height="19">
<font face="华文行楷" size="8">留言板&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</font>
</td>
<td width="275" height="19">
<a href="select_record_gue.asp">
首页</a>&nbsp;&nbsp; <a href="add_record_gue.htm"> 留言</a>&nbsp;&nbsp;
<a href="logon.asp">删除</a>&nbsp;&nbsp;<a href="sele_modi_record_gue.asp"> 修改</a> &nbsp;&nbsp;<a href="logout.asp">退出</a>
</td>
</tr>
<tr>
<td colspan="2" width="607" height="1">
<hr>
</td>
</tr>
</table>
&nbsp;&nbsp;&nbsp;&nbsp;
<h3>请修改留言:</h3>

<!--表单与记录集的连接-->
<form method="POST" action="modify_record_gue.asp">
<p>
留言主题,<input type="text" name="txtSubject" size="45" value="<% =rsMessages("subject") %>">
</p>
<p>
留言者:<% =rsMessages("username") %>
</p>
<p>
留言时间:<% =rsMessages("date") %>
</p>
<p>
留言内容:
</p>
<p>
<textarea name="txtContent" rows="5" cols="56"><% =rsMessages("content") %></textarea>
</p>
<p>
<input type="hidden" name="txtId" value="<% =rsMessages("id") %>">
<input type="submit" value="保存" name="btnSave"><input type="reset" value="全部重填">
</p>

</form>
</body>
</html>