User Guide
66 Developing Web Applications with ColdFusion
4 UPDATE Employees
4 SET Firstname=’#Form.Firstname#’,
4 LastName=’#Form.LastName#’,
4 Department_ID=’#Form.Department_ID#’
4 StartDate=’#Form.StartDate#’>
4 Salary=#Form.Salary#>
WHERE Employee_ID=#Employee_ID#
</CFQUERY>
<H1>Employee Added</H1>
<CFOUTPUT>
You have updated the information for #Form.FirstName# #Form.LastName#
in the Employees database.
</CFOUTPUT>
3. Save the page. as updatepage.cfm.
4. View
updateform.cfm in a browser, enter values, and click the Submit button.
5. The data is updated into the Employees table and the message appears.
Code Review
Deleting Data
Deleting data in a database can be done with a single delete page. The delete page
contains a CFQUERY tag with a SQL delete statement.
To delete one record from a database:
1. Open the file updateform.cfm in Studio.
2. Modify the file by changing the FORM tag so that it appears as follows:
<FORM ACTION="deletepage.cfm" METHOD="Post">
3. Save the modified file as deleteform.cfm.
4. Create a new application page in Studio.
Code Description
<CFQUERY NAME="UpdateEmployee"
DATASOURCE="CompanyInfo">
UPDATE Employees
SET Firstname=’#Form.Firstname#’,
LastName=’#Form.LastName#’,
Department_ID=’#Form.Department_ID#’
StartDate=’#Form.StartDate#’>
Salary=#Form.Salary#>
WHERE Employee_ID=#Employee_ID#
</CFQUERY>
After the SET clause, you must name a table column.
Then, you indicate a constant or expression as the
value for the column.
Be sure to remember the WHERE statement. If you
do not use it, If you do not use it, the SQL UPDATE
statement will apply the new information to every
row in the database.