Programming instructions

Completing the Trip Maintenance application 137
<cfupdate datasource="CompassTravel" tablename="Trips">
<cflocation url="tripdetail.cfm?ID=#Form.tripID#">
</cfif>
Reviewing the code
The following tables describes the cfinsert and cfupdate code:
Exercise: update trip data using cfupdate
In this exercise, you will add the code to update the trip data into the database. You will
add the
cfupdate tag to the tripeditaction.cfm page.
To update the database using cfupdate:
1 In an editor, open tripeditaction3.cfm from the solutions directory.
2 Review the code to update the database (the last 12 lines of code).
3 Verify that the correct photolocation path is specified. This path is specified in the
<cfset PhotoLocation = "C:..."> tag.
For example, depending on your web server configuration, the photolocation path
might be:
For MS Windows systems:
<cfset PhotoLocation
"C:\cfusionmx\wwwroot\CFDOCS\getting_started\Photos\">
or
<cfset PhotoLocation =
"C:\Inetpub\wwwroot\CFDOCS\getting_started\Photos\">
For Linux or Solaris systems:
<cfset PhotoLocation = "/opt/coldfusionmx/wwwroot/cfdocs/
getting_started/photos/">
or
<cfset PhotoLocation = "/<webserverdocroot>/cfdocs/
getting_started/photos/">
4 Save the file as tripeditaction.cfm in the my_app directory.
Code Explanation
<cfif not isdefined("form.tripID")>
<cfinsert datasource="CompassTravel"
tablename="Trips">
<cflocation url="tripdetail.cfm">
<cfelse>
<cfupdate datasource="CompassTravel"
tablename="Trips">
<cflocation url="tripdetail.cfm?ID=#Form.tripID#">
</cfif>
The ColdFusion function IsDefined
determines whether the hidden field
tripID was passed to the action page
from tripedit.cfm. If there is a current
trip, the isDefined function returns
True. When there is no current trip,
the cfif statement is True. When the
cfif statement is True , the cfinsert
tag executes and the main page
displays with the updated trip. If the
cfif statement evaluates to False, the
cfinsert statement executes and the
first trip displays in the main page.