User Guide

Table Of Contents
486 Chapter 21: Updating Your Database
WHERE Emp_ID = #Form.Emp_ID#
</cfquery>
<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.
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
4.
Enter new values in any of the fields, and click Update Information.
ColdFusion updates the record in the Employee table with your new values and displays a
confirmation message.
When the
cfquery tag retrieves date information from a Microsoft Access database, it displays
the date and time with tenths of seconds, as follows:
This example uses the
Left function to trim the two final characters. The cfdocexamples data
source connects to company.mdb.
Reviewing the code
The following table describes the highlighted code and its function:
Code Description
<cfquery name="UpdateEmployee"
datasource="cfdocexamples">
UPDATE Employee
SET FirstName = '#Form.Firstname#',
LastName = '#Form.LastName#',
Dept_ID = #Form.Dept_ID#,
StartDate =
'#left(Form.StartDate,19)#',
Salary = #Form.Salary#
WHERE Emp_ID = #Form.Emp_ID#
</cfquery>
Updates the specified columns in the record in
the Employee table of the cfdocexamples
database that matches the primary key (Emp_ID).
Because #Form.Dept_ID#, #Form.Salary#, and
#Form.Emp_ID# are numeric, they do not need
to be enclosed in quotation marks.
Because of the way
cfquery gets and displays
dates from Access databases, you use the
Left
function to trim the returned value.