Realization of mailing list function in ASP environment (III.) (recommended)

Source: Internet
Author: User
Tags header include
The mailing list must be authenticated before accessing the Administration page. In this implementation we use the Secure.htm page shown in Figure 3 for the administrator to enter the identification code, and if the user enters a value that is not empty, use cookies to save it. The page that performs the administrative task is admin.asp, and whenever the user attempts to access the page, the following code checks to see if the cookie matches the user ID (here is 123456), and redirects the user to the Secure.htm page where the identification code is entered, if the match fails.

"Figure 3 Aspmailinglist_3.gif"



<%
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 '
%>

Once the administrator's authentication passes, the actions they can perform through admin.asp include:

View all records in the guests table
Edit or
Delete the specified record
Send a message to a user in all mailing lists
The admin page admin.asp as shown in Figure 4. When you display records for a guests table, you extract the records from the database and then use a For each ... The next structure traverses the field collection of the recordset, extracts the field names, and sets the table header. We no longer display the guest_id field on this page, but each user record is preceded by a link to the delete and edit features. The User name field Guest_name and the Mail field Guest_email are converted to mailto links, and click the name to send the message to the user individually. Other fields to be formatted include whether to send a message (mail_list) and a user's message (guest_comment). The code to generate the header is:

"Figure 4 Aspmailinglist_4.gif"



' Select records from the database
Strsql_select = "Select guests.guest_id, Guests.guest_email," & _
"Guests.guest_name, Guests.mail_list," & _
"Guests.guest_comment, Guests.sign_date" & _
"From Guests to 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
... Database null prompt, slightly ...
Else
Rsgbook.movefirst
%>
< table border= "0" cellpadding= "5" cellspacing= "2" align= "Center" >
< tr>
<% in Rsgbook.fields
If Head.name = "guest_id" then%>
... "delete" and "edit" table header, slightly ...
<% Else%>
< TD valign= "middle" align= "center" >< Font face=arial size=2>
<% Select Case Head.name
Case "Guest_name"
Response.Write "Name."
Case "Mail_list"
Response.Write "Mailing List"
Case "Guest_comment"
Response.Write "Message"
End Select
%>
</font>< hr></TD>
<% End If ' head.name = ' guest_id '
Next%>
</tr>

To display the user registration record in the rest of the table, we iterate through all the fields of all records with two nested loops, that is, in a do while ... Inside the loop, embed a For each ... Next Loop. The formatting of the data is put in for each ... Next loop. Its implementation code classes such as:

<% do rsgbook.eof%>
< tr>
<% for per Field in Rsgbook.fields
If Field.name = "guest_id" then%>
< TD valign= "middle" align= "center" >
... Delete feature links, slightly ...



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.