Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 429

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

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Accessing and Using Data
3
View update_form.cfm in your web browser by specifying the page URL and an Employee ID; for example, enter
the following: http://localhost/myapps/update_form.cfm?Emp_ID=3
Note: Although you can view an employee's information, code an action page before you can update the database. For
more information, see
"Creating an action page to update
Reviewing the code
The following table describes the code and its function:
Code
<cfquery name="GetRecordtoUpdate"
datasource="cfdocexamples">
SELECT * FROM Employee
WHERE Emp_ID = #URL.Emp_ID#
</cfquery>
<cfoutput query="GetRecordtoUpdate">
...
</cfoutput>
<form action="update_action.cfm" method="Post">
...
</form>
<input type="Hidden" name="Emp_ID"
value="#Emp_ID#"><br>
First Name:
<input type="text" name="FirstName"
value="#FirstName#"><br>
Last Name:
<input type="text" name="LastName"
value="#LastName#"><br>
Department Number:
<input type="text" name="Dept_ID"
value="#Dept_ID#"><br>
Start Date:
<input type="text" name="StartDate"
value="#StartDate#"><br>
Salary:
<input type="text" name="Salary"
value="#Salary#"><br>
Contracto r:
< cfif #Contract# IS "Yes">
<input type="checkbox"
name="C ontract"
checked>Yes<br>
<cfelse>
<input type="checkbox" name="Contract"> Yes <br>
</cfif>
<br>
<input type="Submit" value="Update Information">
</form>
</cfoutput>
Creating an action page to update data
You can create an action page to update data with either the
Creating an update action page with cfupdate
The
tag is the easiest way to handle simple updates from a front-end form. The
cfupdate
identical syntax to the
cfinsert
data" on page 424.
Description
Queries the cfdocexamples data source and returns records in which
the employee ID matches what was entered in the URL that called this
page.
Makes available as variables the results of the GetRecordtoUpdate
query in the form created in subsequent lines.
Creates a form whose variables are processed on the
update_action.cfm action page.
Uses a hidden input field to pass the Emp_ID (primary key) value to
the action page.
Populates the fields of the update form. This example does not use
ColdFusion formatting functions. As a result, start dates look like
1985-03-12 00:00:00 and salaries do not have dollar signs or commas.
The user can replace the information in any field using any valid input
format for the data.
The Contract field requires special treatment because a check box
appears and sets its value. The cfif structure puts a check mark in the
check box if the Contract field value is
otherwise.
cfupdate
tag.
Last updated 1/20/2012
Yes
, and leaves the box empty
tag or
with the UPDATE statement.
cfquery
cfupdate
424
tag has an almost

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents