Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 430

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Accessing and Using Data
To use the
tag, include the primary key fields in your form submittal. The
cfupdate
detects the primary key fields in the table that you are updating and looks for them in the submitted form fields.
ColdFusion uses the primary key fields to select the record to update (therefore, you cannot update the primary key
value itself). It then uses the remaining form fields that you submit to update the corresponding fields in the record.
Your form only needs to have fields for the database fields that you want to change.
Create a ColdFusion page with the following content:
1
<html>
<head>
<title>Update Employee</title>
</head>
<body>
<cfif not isdefined("Form.Contract")>
<cfset form.contract = "N">
<cfelse>
<cfset form.contract = "Y">
</cfif>
<cfupdate datasource="cfdocexamples" tablename="EMPLOYEE">
<h1>Employee Updated</h1>
<cfoutput>
You have updated the information for #Form.FirstName# #Form.LastName# in the employee
database.
</cfoutput>
</body>
</html>
2
Save the page as update_action.cfm.
View update_form.cfm in your web browser by specifying the page URL and an Employee ID; for example, enter
3
the following: http://localhost/myapps/update_form.cfm?Emp_ID=3
Enter new values in any of the fields, and click Update Information.
4
ColdFusion updates the record in the Employee table with your new values and displays a confirmation message.
Reviewing the code
The following table describes the code and its function:
Code
<cfif not isdefined("Form.Contract")>
<cfset Form.contract = "N">
<cfelse>
<cfset form.contract = "Y">
</cfif>
<cfupdate datasource="cfdocexamples"
tablename="EMPLOYEE">
<cfoutput>
You have updated the information for
#Form.FirstName# #Form.LastName# in the employee
database.
</cfoutput>
Description
Sets the value of
Form.Contract
defined. If the Contractor check box is unchecked, no value is passed to the
action page; however, the database field must have some value.
Updates the record in the database that matches the primary key on the
form (Emp_ID). Updates all fields in the record with names that match the
names of form controls.
Informs the user that the change was made successfully.
Last updated 1/20/2012
tag automatically
cfupdate
to
if it is not defined, or to
if it is
No
Yes
425

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents