![MACROMEDIA COLDFUSION 5-DEVELOPING Develop Manual Download Page 126](http://html1.mh-extra.com/html/macromedia/coldfusion-5-developing/coldfusion-5-developing_develop-manual_3293641126.webp)
106
Chapter 7 Updating Your Database
Reviewing the code
The following table describes the highlighted code and its function:
Updating Data
You usually use two application pages to update data in a database:
•
An update form
•
An update action page
You can create an update form with
cfform
tags or HTML form tags. The update
form calls an update action page, which can contain either a
cfupdate
tag or a
cfquery
tag with a SQL UPDATE statement. The update action page should also
contain a message for the end user that reports on the update completion.
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 Emp_ID would be unique to each record.
•
An update form is usually populated with existing record data because the form’s
purpose is to update 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.
Code
Description
<cfquery name="AddEmployee"
datasource="CompanyInfo">
INSERT INTO Employee
VALUES (’#Form.Emp_ID#’,
’#Form.FirstName#’,
’#Form.LastName#’,
’#Form.Dept_ID#’,
’#Form.StartDate#’,
’#Form.Salary#’,
’#Form.Contract#’)
</cfquery>
Use a
cfquery
tag to insert a new row
into the Employee table of the
CompanyInfo Database. Specify each
form field to be added. Because the form
and database field names are identical,
you do not have to specify the database
field names in the query.
Summary of Contents for COLDFUSION 5-DEVELOPING
Page 1: ...Macromedia Incorporated Developing ColdFusion Applications MacroMedia ColdFusion 5 ...
Page 58: ...38 Chapter 3 Querying a Database ...
Page 134: ...114 Chapter 7 Updating Your Database ...
Page 210: ...190 Chapter 10 Reusing Code ...
Page 232: ...212 Chapter 11 Preventing and Handling Errors ...
Page 238: ...218 Chapter 12 Using the Application Framework ...
Page 262: ...242 Chapter 12 Using the Application Framework ...
Page 278: ...258 Chapter 13 Extending ColdFusion Pages with CFML Scripting ...
Page 320: ...300 Chapter 15 Indexing and Searching Data ...
Page 336: ...316 Chapter 16 Sending and Receiving E mail ...
Page 374: ...354 Chapter 18 Interacting with Remote Servers ...