Updating Data - Adobe 38043740 - ColdFusion Standard - Mac Development Manual

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

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Accessing and Using Data
Inserting into specific fields
The preceding example inserts data into all the fields of a table (the Employee table has seven fields). There might be
times when you do not want users to add data into all fields. To insert data into specific fields, the SQL statement in
the
must specify the field names following both INSERT INTO and VALUES. For example, the following
cfquery
omits salary and start date information from the update. Database values for these fields are 0 and NULL,
cfquery
respectively, according to the database's design.
<cfquery name="AddEmployee" datasource="cfdocexamples">
INSERT INTO Employee
(Emp_ID,FirstName,LastName,
Dept_ID,Contract)
VALUES
(#Form.Emp_ID#,'#Form.FirstName#','#Form.LastName#',
#Form.Dept_ID#,'#Form.Contract#')
</cfquery>

Updating data

You usually use the following two application pages to update data in a database:
• An update form
• An update action page
You can create an update form with
which can contain either a
cfupdate
should also contain a confirmation message for the end user.
Creating an update form
The following are the key differences between an update form and an insert form:
• An update form contains a reference to the primary key of the record that is being updated.
A primary key is a fields in a database table that uniquely identifies each record. For example, in a table of employee
names and addresses, only the Emp_ID is unique to each record.
• An update form is 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.
Create a ColdFusion page with the following content:
1
tags or HTML form tags. The update form calls an update action page,
cfform
tag or a
tag with a SQL UPDATE statement. The update action page
cfquery
Last updated 1/20/2012
422

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents