User Guide
126 Chapter 10: Lesson 6: Adding and Updating SQL Data
Notice that when the user clicks the Add button, the maintenanceaction.cfm navigates to
tripedit.cfm passing no arguments. Conversely, when the user clicks the Edit button, the Trip
Edit page passes the current record id. The Trip Edit page must handle both cases. When a
RecordID is passed on the URL, tripedit.cfm must query the database and fill the form with the
data for the corresponding trip. The following code properly initializes the trip edit form:
<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")>
<cfset price = #TripQuery.price#>
<cfset tripLeader = '#TripQuery.tripLeader#'>
<cfset photo = '#TripQuery.photo#'>
<cfset baseCost = #TripQuery.baseCost#>
<cfset numberPeople = #TripQuery.numberPeople#>
<cfset depositRequired = '#TripQuery.depositRequired#'>
<cfelse>
<cfset tripName = ''>
<cfset eventType = ''>
<cfset tripDescription = ''>
<cfset eventTypeIdentifier = #TripQuery.eventType#>
<cfset tripLocation = ''>
<cfset departureDate = ''>
<cfset returnDate = ''>
<cfset price = ''>
<cfset tripLeader = ''>
<cfset photo = ''>
<cfset baseCost = ''>
<cfset numberPeople = ''>
<cfset depositRequired = ''>
</cfif>