System information

Exercise 4: Updating a SQL row using the cfupdate tag 137
3.
To verify that the trip was saved, open the tripsearchform.cfm page in the my_app directory in
your browser.
4.
In the Trip Search page, in the Trip Location drop-down list, select the Begins With option,
and enter the value Nor in the text box.
5.
Click Search.
The TripResults page appears.
6.
Click NH White Mountains to display the details of the trip you just added. Verify that all the
fields were saved correctly.
For more information about adding data to a database using the
cfinsert tag, see ColdFusion
MX Developer’s Guide.
Exercise 4: Updating a SQL row using the cfupdate tag
To update an existing SQL row, ColdFusion offers a simple approach through the use of the
cfupdate tag. Like the cfinsert tag, the cfupdate tag has datasource and tablename
attributes to specify where the data is to be inserted. The tag also has a formfields attribute to
identify which fields are to insert. The
formfields attribute specifies a comma-separated list of
form fields to insert. If this attribute is not specified, all the fields in the form are included in the
operation.
All the fields of the tripedit.cfm page have corresponding columns in the Trips table, so you can
omit the
FormFields attribute for both the cfinsert and cfupdate tags. If the tripID form
field is passed from the Trip Edit page, the
cfupdate tag is used; otherwise the cfinsert tag is
executed. The following example uses the
cfupdate and cfinsert tags without the formfields
attribute:
<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>