User Guide
108 Chapter 7 Updating Your Database
Reviewing the code
The following table describes the code and its function:
Code Description
<cfquery name="GetRecordtoUpdate"
datasource="CompanyInfo">
SELECT *
FROM Employee
WHERE Emp_ID = #URL.Emp_ID#
</cfquery>
Query the CompanyInfo data source
and return the records in which the
employee ID matches what was
entered in the URL that called this
page.
<cfoutput query="GetRecordtoUpdate">
Make the results of the
GetRecordtoUpdate query available
as variables in the form created on
the next line.
<form action="updateaction.cfm"
method="Post">
Create a form whose variables will
be processed on the
updateaction.cfm action page.
<input type="Hidden" name="Emp_ID"
value="#Emp_ID#"><br>
Use a hidden input field to pass the
employee ID to the action page.
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>
Populate the fields of the update
form. This example does not use any
ColdFusion formatting functions to
“clean up” the form. As a result, the
start dates look like 1985-03-12
00:00:00 and the 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.
Contractor:
<cfif #Contract# IS "Yes">
<input type="checkbox" name="Contract"
checked>Yes<br>
<cfelse>
<input type="checkbox" name="Contract">
Yes <br>
</cfif>
<br>
<input type="Submit" value="Update
Information">
</form>
</cfoutput>
The Contractor field needs special
treatment because a check box
displays and sets its value. Use the
cfif structure to put a check mark in
the check box if the Contract field
value is Yes, and leave the box
empty otherwise.