Programming instructions
142 Lesson 6 Adding and Updating SQL Data
3 Add the following code:
<!---Routine to increase trip price by 10% --->
<cfquery name="TripQuery" dataSource="CompassTravel">
UPDATE trips SET price = price * 1.1
</cfquery>
<cfoutput> New prices are now in effect.</cfoutput>
4 Save the page then test the page by doing the following tasks:
a Use the Trip Maintenance application to take note of the price of any trip by
viewing tripdetail.cfm in a browser.
b Test by opening the priceincrease.cfmpage in your browser. This page
automatically updates the prices in the trips table.
c Use the Trip Maintenance application to verify that the query successfully
increased the price of the trip by 10%. To do this, navigate to the tripdetail.cfm
and locate the trip you noted in step 4a. The price of this trip is now 10% higher.
Summary
In this lesson you used the cfinsert and cfupdate tags to add and update data to a
SQL table. You also have used the SQL UPDATE statement in conjuction with the
cfquery tag to effect a trip price increase for all rows in the Trips table.
You have completed the Getting Started tutorial. You should understand how you can
combine CFML and SQL to develop powerful applications. When compared with
traditional development methods, ColdFusion helps speed the development in hand
crafting a database solution like the one in this tutorial. Remarkably, however, depending
on the editor or IDE that you use to develop applications, much of the work in this
tutorial can be autogenerated using built-in wizards, which simplifies the development
process even more.