Creating An Action Page To Update Data - MACROMEDIA COLDFUSION 4.5-DEVELOPING WEB Develop Manual

Developing web applications with coldfusion
Table of Contents

Advertisement

Chapter 6: Updating Your Data

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"
<HTML>
<HEAD>
</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
4.
View
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">
TABLENAME="Employees">
<TITLE>Update Employee</TITLE>
updatepage.cfm
in a browser, enter values, and click the Submit button.
updateform.cfm
.
65

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 4.5

Table of Contents