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

Source: Internet
Author: User
Tags header include
You 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.

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



' 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 ...
</td>
< TD valign= "middle" align= "center" >
... Edit feature links, slightly ...
</td>
<% Else%>
< TD valign= "middle" align= "center" >
<% if IsNull (Field) Then
Response.Write ""
Else
If Field.name = "Guest_name" Then
Response.Write ... User name of the mailto link, slightly ...
ElseIf field.name = "Mail_list" Then
... Output "yes" or "no", slightly ...
ElseIf field.name = "Guest_comment" Then
... Output user message, slightly ...
End If ' Field.name
End If ' IsNull (Field)%>
</td>
<% End If ' field.name = ' guest_id '
Next
Rsgbook.movenext%>
</tr>
<% loop%>
</table>

Now we have the database records displayed in the table. Click a graphical link in the table to access edit_record.asp and delete_record.asp, which provide the editing and deletion of records respectively. First, let's take a look at the implementation of the deletion feature:

<%
Iguestid = Request.QueryString ("ID")
If Iguestid < > "" Then
' Deletes records identified by ID from the database
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 < > ' "
%>

The code above is very similar to the code in unsubscribe.asp, and in fact the tasks that are done are similar. The ID here is required, which identifies the record that is required for deletion. The actual delete task is completed by the Delete SQL command.

The code used to update the record page edit_record.asp is slightly more complex, as shown in Figure 5. There are two SQL statements to be used: the first SQL SELECT statement selects the records that need to be edited from the database, and the second SQL UPDATE statement saves the results of the administrator edits to the database. Here we do not specifically analyze the implementation process, see the code attached to this article and its comments.


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.