Programming instructions

Completing the Trip Maintenance application 139
<cfset eventTypeIdentifier = #TripQuery.eventType#>
<cfset tripLocation = ''>
<cfset departureDate = ''>
<cfset returnDate = ''>
<cfset price = ''>
<cfset tripLeader = ''>
<cfset photo = ''>
<cfset baseCost = ''>
<cfset numberPeople = ''>
<cfset depositRequired = ''>
</cfif>
Reviewing the code
The following table describes the code used to properly initialize the trip edit form:
Exercise: linking the Add and Edit buttons
In this exercise you will link the Add and Edit buttons on the Trip Detail page with the
Trip Edit page.
To link the add and update buttons on the Trip Detail page:
1 Open maintenanceaction.cfm in the my_app directory in your editor.
2Locate the
</cfif> tag at the end of the file.
Code Explanation
<cfif IsDefined("URL.ID")>
<cfquery name="TripQuery" datasource="CompassTravel"
maxrows="1">
SELECT tripName, eventType, tripDescription,
tripLocation, departureDate, returnDate, price,
tripLeader, photo, baseCost, numberPeople,
depositRequired, tripID
FROM trips
<cfif IsDefined("URL.ID")>
WHERE tripID = #ID#
</cfif>
</cfquery>
<!-- Set the local variables -->
<cfset tripName = '#TripQuery.tripName#'>
<cfset eventType = #TripQuery.eventType#>
<cfset tripDescription =
TripQuery.tripDescription#'>
<cfset tripLocation = '#TripQuery.tripLocation#'>
<cfset departureDate =
DateFormat(#TripQuery.departureDate#,"mm/dd/yyyy")>
<cfset returnDate =
DateFormat(#TripQuery.returnDate#,"mm/dd/yyyy")>
...
<cfelse>
<cfset tripName = ''>
<cfset eventType = ''>
...
</cfif>
The ColdFusion function
IsDefined determines whether an
ID argument was passed as part of
the invoking URL.
The ID argument is passed when
TripEdit is invoked when the Edit
button is clicked on the main page.
When an ID is passed, it is used in
the WHERE clause of the SQL
SELECT statement to retrieve the
information about the current trip.
The program then instantiates local
variables from the results of the
SQL query.
ColdFusion DateFormat function
formats the date fields.
If TripEdit is called to add a new trip,
then there is no ID passed as a URL
argument. In this case, the local
variables are instantiated to blank.