System information

142 Chapter 12: Lesson 9: Enabling Database Maintenance
Reviewing the code
The following table describes the code that ColdFusion uses to properly initialize the Trip Edit
form:
To test the modified code:
1.
Open the tripdetail.cfm page in your browser.
2.
Do the following tasks:
a
Click the Edit button.
b
Double the price of the current trip.
c
Click Save.
Summary
In this lesson you used the SQL DELETE statement, and the cfinsert and cfupdate tags to
delete, add, and update data to a table.
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.
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 application
then instantiates local variables from
the results of the SQL query. The
ColdFusion
DateFormat function
formats the date fields.
If the user clicks the Add button to add
a new trip, there is no ID passed as a
URL argument. In this case, the local
variables are instantiated to blank.