To delete one record from a database:
In update_form.cfm, change the title to "Delete Form" and the text on the submit button to
1
"Delete Record".
Change the
tag so that it appears as follows:
2
form
<form action="delete_action.cfm" method="Post">
Save the modified file as delete_form.cfm.
3
Create a ColdFusion page with the following content:
4
<html>
<head>
<title>Delete Employee Record</title>
</head>
<body>
<cfquery name="DeleteEmployee"
datasource="CompanyInfo">
DELETE FROM Employee
WHERE Emp_ID = #Form.Emp_ID#
</cfquery>
<h1>The employee record has been deleted.</h1>
<cfoutput>
You have deleted #Form.FirstName# #Form.LastName# from the
employee database.
</cfoutput>
</body>
</html>
Save the page as delete_action.cfm.
5
View delete_form.cfm in your web browser by specifying the page URL and an Employee ID;
6
for example, enter the following:
http://localhost/myapps/delete_form.cfm?Emp_ID=3.Click Delete Record.
ColdFusion deletes the record in the Employee table and displays a confirmation message.
Reviewing the code
The following table describes the code and its function:
Code
<cfquery name="DeleteEmployee"
datasource="CompanyInfo">
DELETE FROM Employee
WHERE Emp_ID = #Form.Emp_ID#
</cfquery>
<cfoutput>
You have deleted #Form.FirstName#
#Form.LastName# from the
employee database.
</cfoutput>
Description
Deletes the record in the database whose Emp_ID
column matches the Emp_ID (hidden) field on the form.
Since the Emp_ID is the table's primary key, only one
record is deleted.
Informs the user that the record was deleted.
Deleting data
449
Need help?
Do you have a question about the COLDFUSION MX 61-DEVELOPING COLDFUSION MX and is the answer not in the manual?
Questions and answers