Review: Guest Book Database and Form
In Tutorial 2, we created a database (visualtutorial.mdb) and designed a guest book table (GuestBook) for our database. ( Figure 3 shows the GuestBook table. Look familiar?)
Figure 3 GuestBook table design.
Then in Tutorial 3, we populated the GuestBook table with data entered manually and by using SQL commands.
In Tutorial 4, we created an HTML form (guestbook.html) to get guest book–related information from our users. Listing 1 shows the code for this form.
Listing 1 HTML Code for GuestBook.html
<FORM METHOD=POST ACTION="insert.asp"> <CENTER> <FONT FACE="ARIAL" STYLE="font-size:18pt" COLOR=MAROON> <B>Sign My Guest Book!</B> </FONT> <TABLE BORDER=1 CELLSPACING=0 BORDERCOLOR=MAROON><TR><TD> <TABLE CELLSPACING=0 BORDER=0> <TR> <TD BGCOLOR=TAN> <FONT FACE="ARIAL" STYLE="font-size:9pt"><B> Name: </B></FONT> </TD> <TD><INPUT TYPE=TEXT NAME=name SIZE=40></TD> </TR> <TR> <TD BGCOLOR=TAN> <FONT FACE="ARIAL" STYLE="font-size:9pt"><B> E-mail: </B></FONT> </TD> <TD><INPUT TYPE=TEXT NAME=email SIZE=40></TD> </TR> <TR> <TD BGCOLOR=TAN></TD> <TD> <INPUT TYPE=CHECKBOX NAME=hideEmail VALUE="yes" CHECKED> <FONT FACE="ARIAL" STYLE="font-size:9pt"> Hide E-mail? </FONT> </TD> </TR> <TR> <TD BGCOLOR=TAN> <FONT FACE="ARIAL" STYLE="font-size:9pt"><B> Age: </B></FONT> </TD> <TD><INPUT TYPE=TEXT NAME=age SIZE=3 VALUE="18"></TD> </TR> <TR> <TD VALIGN=TOP BGCOLOR=TAN> <FONT FACE="ARIAL" STYLE="font-size:9pt"><B> Gender: </B></FONT> </TD> <TD> <INPUT TYPE=RADIO NAME=gender VALUE="male"> <FONT FACE="ARIAL" STYLE="font-size:9pt"> Male </FONT> <BR> <INPUT TYPE=RADIO NAME=gender VALUE="female" CHECKED> <FONT FACE="ARIAL" STYLE="font-size:9pt"> Female </FONT> </TD> </TR> <TR> <TD VALIGN=TOP BGCOLOR=TAN> <FONT FACE="ARIAL" STYLE="font-size:9pt"><B> Comment: </B></FONT> </TD> <TD> <TEXTAREA NAME=comment ROWS=5 COLS=40 STYLE="font-family:Arial"> Insert a Comment Here </TEXTAREA> </TD> </TR> </TABLE> </TD></TR></TABLE> <INPUT TYPE=SUBMIT VALUE="SIGN MY GUEST BOOK"> </CENTER> </FORM>
Pay particular attention to the control names (shown in bold in Listing 1), which are the same as the table field names. We'll finally get to use these names in the ASP insert script. When opened in a browser, guestbook.html displays the form shown in Figure 4.
Figure 4 Browser: Filling out the form.
Suppose the user enters the data shown in Figure 4. When he or she clicks the SIGN MY GUEST BOOK button, the browser displays the form shown in Figure 5.
Figure 5 Browser: After clicking the SIGN MY GUEST BOOK button.
This form doesn't just appear magically. We build it with the help of two ASP scripts:
An insert script (insert.asp), which puts the user's information into the database
A retrieve script (retrieve.asp), which gets information out of the database and displays it on the user's browser
Before looking at the specific details of the insert and retrieve scripts, we'll discuss some general properties of Active Server Pages scripts.