Chapter 6: Updating Your Data
65
Creating an Action Page to Update Data
You can create an action page to update data with either the CFUPDATE tag or
CFQUERY with the UPDATE statement.
The CFUPDATE tag is the easiest way to handle simple updates from a front end form.
The CFUPDATE tag has an almost identical syntax to the CFINSERT tag.
To use CFUPDATE, you must include all of the fields that make up the primary key in
your form submittal. The CFUPDATE tag automatically detects the primary key fields
in the table you are updating and looks for them in the submitted form fields.
ColdFusion uses the primary key field(s) to select the record to update. It then updates
the appropriate fields in the record using the remaining form fields submitted.
For more complicated updates, you can use a SQL UPDATE statement in a CFQUERY
tag instead of a CFUPDATE tag. The SQL update statement is more flexible for
complicated updates.
To create an update page with CFUPDATE:
1.
Create a new application page in Studio.
2.
Enter the following code:
4
<CFUPDATE DATASOURCE="CompanyInfo"
TABLENAME="Employees">
<HTML>
<HEAD>
<TITLE>Update Employee</TITLE>
</HEAD>
<BODY>
<H1>Employee Added</H1>
<CFOUTPUT>
You have updated the information for #Form.FirstName# #Form.LastName#
in the Employees database.
</CFOUTPUT>
</BODY>
</HTML>
3.
Save the page. as
updatepage.cfm
.
4.
View
updateform.cfm
in a browser, enter values, and click the Submit button.
5.
The data is updated in the Employees table and the message appears.
To create an update page with CFQUERY:
1.
Create a new application page in Studio.
2.
Enter the following code:
4
<CFQUERY NAME="UpdateEmployee"
4
DATASOURCE="CompanyInfo">
Summary of Contents for COLDFUSION 4.5-DEVELOPING WEB
Page 1: ...Allaire Corporation Developing Web Applications with ColdFusion ColdFusion 4 5...
Page 14: ...xiv Developing Web Applications with ColdFusion...
Page 26: ...xxvi Developing Web Applications with ColdFusion...
Page 34: ...8 Developing Web Applications with ColdFusion...
Page 70: ...44 Developing Web Applications with ColdFusion...
Page 84: ...58 Developing Web Applications with ColdFusion...
Page 114: ...88 Developing Web Applications with ColdFusion...
Page 148: ...122 Developing Web Applications with ColdFusion...
Page 174: ...148 Developing Web Applications with ColdFusion...
Page 208: ...182 Developing Web Applications with ColdFusion...
Page 244: ...218 Developing Web Applications with ColdFusion...
Page 274: ...248 Developing Web Applications with ColdFusion...
Page 288: ...262 Developing Web Applications with ColdFusion...
Page 300: ...274 Developing Web Applications with ColdFusion...
Page 350: ...324 Developing Web Applications with ColdFusion...
Page 362: ...336 Developing Web Applications with ColdFusion...