< %
strPW1 = Request.Form("txtPW")
if strPW1 < > "" then
Response.Cookies("PassWord") = strPW1
end if 'strPW1 < > ""
strPW2 = Request.Cookies("PassWord")
If strPW2 < > "123456" Then
Response.Redirect("secure.htm")
End if 'strPW2 < > "123456"
%>
一旦办理员的身份验证经由过程,他们可以经由过程Admin.asp履行的操作包含:
检查Guests表中的一切纪录
编纂或
删除指定的纪录
向一切邮件列表中的用户发送邮件
办理页面admin.asp如图4所示。显示Guests表的纪录时先从数据库提取这些纪录,然后利用一个For Each ... Next布局遍历纪录集的字段纠合,提取字段名字并设置表格的表头。在这个页面中咱们不再显示Guest_ID字段,但每一个用户纪录的后面都加上了一个“删除”和“编纂”功效的链接。用户名字字段Guest_Name与邮件字段Guest_Email被转换为mailto链接,单击名字可以独自向该用户发送邮件。其它要格局化的字段还包含是不是发送邮件(Mail_List)和用户留言(Guest_Comment)。生成表头的代码为:
' 从数据库拔取纪录
strSQL_Select = "SELECT Guests.Guest_ID, Guests.Guest_Email, " & _
" Guests.Guest_Name, Guests.Mail_List, " & _
" Guests.Guest_Comment, Guests.Sign_Date " & _
" FROM Guests ORDER BY Guests.Guest_Name; "
Set oConn=Server.CreateObject("ADODB.Connection")
oConn.Open strDSNPath
Set rsGbook = oConn.Execute(strSQL_Select)
if rsGbook.BOF = True and rsGbook.EOF = True then
...数据库空提醒,略...
else
rsGbook.MoveFirst
%>
< table BORDER="0" cellpadding="5" cellspacing="2" align="center">
< tr>
< % for each Head in rsGbook.Fields
if Head.Name = "Guest_ID" then %>
..."删除"与"编纂"表头,略...
< % else %>
< td VALIGN="middle" align="center">< font face=Arial size=2>
< % select case Head.Name
case "Guest_Name"
Response.Write "名 字"
case "Mail_List"
Response.Write "邮件列表"
case "Guest_Comment"
Response.Write "留 言"
end select
%>
< /font>< HR>< /td>
< % end if 'Head.Name = "Guest_ID"
next %>
< /tr>
为在表格的其他地位显示用户注册纪录,咱们用两个嵌套的轮回遍历一切纪录的一切字段,即在一个Do While ...轮回外面嵌入一个For Each ... Next 轮回。数据的格局化任务放在For Each ... Next轮回内。其完成代码类如:
< % Do While Not rsGbook.EOF %>
< tr>
< % For Each Field in rsGbook.Fields
if Field.Name = "Guest_ID" then %>
< td VALIGN="middle" ALIGN="center">
...删除功效的链接,略...
< /td>
< td VALIGN="middle" ALIGN="center">
...编纂功效的链接,略...
< /td>
< % else %>
< td VALIGN="middle" align="center">
< % if isNull(Field) then
Response.Write " "
else
if Field.Name = "Guest_Name" then
Response.Write ...用户名字的mailto链接,略...
elseif Field.Name = "Mail_List" then
...输入"是"或"否",略...
elseif Field.Name = "Guest_Comment" then
...输入用户留言,略...
end if 'Field.Name
end if 'isNull(Field)%>
< /td>
< % end if 'Field.Name = "Guest_ID"
Next
rsGbook.MoveNext %>
< /tr>
< % loop %>
< /table>
< %
iGuestID = Request.Querystring("ID")
if iGuestID < > "" then
'从数据库删除由ID标识的纪录
strSQL_Delete = "DELETE FROM Guests " & _
" WHERE Guest_ID=" & iGuestID
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open strDSNPath
on error resume next
oConn.Execute strSQL_Delete
oConn.Close
Set oConn = Nothing
if err.number < > 0 then
Response.Redirect("admin.asp?Error_Del=True")
else
Response.Redirect("admin.asp?Error_Del=False")
end if
else
Response.Redirect("admin.asp")
end if 'iGuestID < > ""
%>