User Guide

Table Of Contents
Updating data 481
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 field(s) 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 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 ColdFusion page with the following content:
<html>
<head>
<title>Update Form</title>
</head>
<body>
<cfquery name="GetRecordtoUpdate"
datasource="cfdocexamples">
SELECT * FROM Employee
WHERE Emp_ID = #URL.Emp_ID#
</cfquery>
<cfoutput query="GetRecordtoUpdate">
<table>
<form action="update_action.cfm" method="Post">
<input type="Hidden" name="Emp_ID"
value="#Emp_ID#"><br>
<tr>
<td>First Name:</td>
<td><input type="text" name="FirstName" value="#FirstName#"></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type="text" name="LastName" value="#LastName#"></td>
</tr>
<tr>
<td>Department Number:</td>
<td><input type="text" name="Dept_ID" value="#Dept_ID#"></td>
</tr>
<tr>
<td>Start Date:</td>
<td><input type="text" name="StartDate" value="#StartDate#"></td>
</tr>
<tr>
<td>Salary:</td>
<td><input type="text" name="Salary" value="#Salary#"></td>
</tr>