When served, info.asp will look like this. If you look at the
code for this page, you'll notice there's next to nothing there.
<table width="500">
<form action="info2.asp" method="get">
<tr>
<td width="500" align="center">
<p><!--#include file="carsdown.inc"--> With a <!--#include file="trandown.inc"--> transmission<br>
<br><br><br>
<p><input type="Submit" value="Let Jay Know" align="LEFT">
</td>
</tr>
</form>
If you're a savvy Web developer, however, you'll recognize
<!--#include file="carsdown.inc"--> as an include. This line
simply tells the Web server to import the contents of the file
named carsdown.inc as soon as this document is called. Commonly,
includes are used for headers, footers, and the like.
I've decided to use an include in this instance for two reasons.
First, it cleans up what would otherwise be some messy code.
Plus, I think I'll need a listing of cars on another page. And who
wants to retype? That said, let's look at the code for carsdown.inc.
<%
SQLCAR="SELECT carName, carID FROM Cars"
set conncar = server.createobject("ADODB.Connection")
conncar.open "parking"
set cars=conncar.execute(SQLCAR)
%>
<select name="carID">
<% do while not cars.eof %>
<Option value = "<%= cars(1) %>"> <%= cars(0) %></Option>
<%cars.movenext
loop%>
</select>
<% cars.close %>
Nothing new here, really. All we've done is take several techniques
we went over in Lesson 3 and combine them in one HTML form. We've
created a dropdown box that is generated dynamically from the database.
As cars are added to the database, they will appear in this list.
I'd like you to note one important thing here. The value attribute of
each option will be the value of the carID field. Why? Because we're
after the table's primary key. That, as you might remember, is the basis
for the relationships to other tables.
If you're following along and serving pages at home, enter some values in
these boxes and click the button. Notice how the values are passed to the
querystring.
Time to take on info2.asp.
next page»