Home > Articles > Programming

  • Print
  • + Share This

The Insert Script, Part 3: Redirection

Suppose a user fills out an HTML form on your site and then clicks the submit button. Your insert script opens your database, stores that information in the database, and then closes the database. What happens next? Well, typically either a "Thank You" message pops up on the user's browser or some kind of summary page appears, especially if the form was some kind of survey. How does the "Thank You" message or summary page appear? The answer is that your insert script tells the user's browser to load a new web page. The command to tell the user's browser to load a new web page is shown in Listing 23.

Listing 23 General Code to Redirect the User's Browser to a New Web Page

response.redirect("web page address")

Suppose that after the user fills out our guest book we want him or her to visit the InformIT web site. The last line in the insert script would be the following:


If we want the user to go to a thank-you web page we designed whose name is thankyou.html, the last line in the insert script would read like this:


The above line assumes that thankyou.html is in the same folder as the insert script; that is, thankyou.html is in the same folder as insert.asp on the web server.

In our guest book example, we'll redirect the user to a web page that displays the entire contents of the guest book. An ASP script named retrieve.asp creates this web page. Thus, this is the last line in our insert script:


The completed insert script should looks like Listing 24.

Listing 24 insert.asp: Final Code with Browser Redirect Command

' Step 1: Open the Guest Book
set conn=server.createobject("adodb.connection")
conn.open("DBQ=" & server.mappath("visualtutorial.mdb") & _
     ";Driver={Microsoft Access Driver (*.mdb)};")
' Step 2: Read the user's information
if v_name="" then v_name="anonymous coward"
v_name=replace(v_name, "'", "''")

if v_email="" then v_email="Not specified"
v_email=replace(v_email, "'", "''")

if isnumeric(v_age)=false then v_age=2


if v_comment="" then v_comment="No comment given"
v_comment=replace(v_comment, "'", "''")

if v_hideEmail="" then v_hideEmail="No"
' Step 3: Send a SQL INSERT query
conn.execute("insert into GuestBook "     &_
"(name,email,hideEmail, age,gender,comment) " & _
"Values ("                  & _
    "'" & v_name   & "'," & _
    "'" & v_email   & "'," & _
    " " & v_hideEmail & " ," & _
    " " & v_age    & " ," & _
    "'" & v_gender  & "'," & _
    "'" & v_comment  & "')")
' Step 4: Close the database
set conn=nothing


You're halfway there! Next, we look at how to create the retrieve script: retrieve.asp.

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.