Chapter 6: Updating Your Data
Creating an Update Form
An update form is similar to an insert form, but there are two key differences:
An update form contains a reference to the primary key of the record that is
being updated.
A primary key is a field or combination of fields in a database table that
uniquely identifies each record in the table. For example, in a table of employee
names and addresses, only the Employee_ID would be unique to each record.
Because the purpose of an update form is to update existing data, the update
form is usually populated with existing record data.
The easiest way to designate the primary key in an update form is to include a hidden
input field with the value of the primary key for the record you want to update. The
hidden field indicates to ColdFusion which record to update.
To create an update form:
1.
Create a new page in Studio.
2.
Edit the page so that it appears as follows:
<CFQUERY NAME="GetRecordtoUpdate"
</CFQUERY>
<HTML>
<HEAD>
</HEAD>
<BODY>
<CFOUTPUT QUERY="GetRecordtoUpdate">
<FORM ACTION="UpdatePage.cfm" METHOD="Post">
<INPUT TYPE="Hidden" NAME="Employee_ID"
VALUE="#Department_ID#"><BR>
DATASOURCE="CompanyInfo">
SELECT *
FROM Employees
WHERE Employee_ID = #URL.Employee_ID#
<TITLE>Update Form</TITLE>
VALUE="#Employee_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="Department_ID"
Start Date:
<INPUT TYPE="text" NAME="StartDate" VALUE="#StartDate#"><BR>
Salary:
<INPUT TYPE="text" NAME="Salary" VALUE="#Salary#"><BR>
Contractor:
63
Need help?
Do you have a question about the COLDFUSION 4.5-DEVELOPING WEB and is the answer not in the manual?