Programming instructions
140 Lesson 6 Adding and Updating SQL Data
3 Insert the following code just before the last line:
<!--- EDIT BUTTON --->
<cfelseif IsDefined("Form.btnEdit")>
<cflocation url="tripedit.cfm?ID=#Form.RecordID#">
<!--- ADD BUTTON --->
<cfelseif IsDefined("Form.btnAdd")>
<cflocation url="tripedit.cfm">
</cfif>
4 Save maintenanceaction.cfm.
5 Open tripedit4.cfm in the solutions directory in your editor.
6 Open the file initvariables.txt from the solutions directory.
7 Copy the contents of the initvariables.txt and paste it before the
<HTML> tag in the
tripedit4.cfm page.
8 Save the file as tripedit.cfm in the my_app directory.
9 Test update logic by opening the tripdetail.cfm page in your browser and doing the
following tasks:
a Click the Edit button.
b Double the price of the current trip.
c Click Save.
The ColdFusion
cfupdate works well for updating a single record. To update several
records in a single query, you must use the SQL UPDATE statement in conjuction with
cfquery.
SQL Update
The SQL UPDATE statement updates or changes rows in a relational table. The syntax
of the UPDATE statement is as follows:
UPDATE table_name SET column_name = new_value
WHERE column_name = some_value
Consider a database table named Clients that contains information about people in the
following rows:
PersonID LastName FirstName Age
1GreenTom 12
2Wall Peter 42
3 Madigan Jess 20