欢迎光临
我们一直在努力

ASP环境下邮件列表功能的实现 (三)(推荐)

建站超值云服务器,限时71元/月

在访问管理页面之前必须经过身份验证。本实现中我们用图3所示的secure.htm页面供管理员输入身份识别码,若用户输入值非空则用cookies来保存它。执行管理任务的页面是admin.asp,每当用户试图访问这个页面,下面的代码将检查这个cookies与用户身份识别码(这里是123456)是否匹配,如匹配失败则将该用户重定向到输入身份识别码的secure.htm页面。

 < %

  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>

   现在我们已经把数据库记录显示在表格中了。单击表格中的图形链接可以访问edit_record.asp和delete_record.asp,这两个文件分别提供记录的编辑和删除功能。首先我们来看看删除功能的实现:

 < %

 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 < > ""

 %>

   上述代码与unsubscribe.asp中的代码非常相似,实际上两者完成的任务也很类似。这里的id是必须的,它标识了要求删除的记录。实际的删除任务通过delete sql命令完成。

   更新记录页面edit_record.asp所用的代码稍微复杂一点,其界面如图5所示。这里要用到两个sql语句:第一个sql select语句从数据库选取需要编辑的记录;第二个sql update语句将管理员编辑结果保存到数据库。这里我们不再具体分析实现过程,请参见本文所附代码及其注释。

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ASP环境下邮件列表功能的实现 (三)(推荐)
分享到: 更多 (0)

相关推荐

  • 暂无文章