Chapter 6: Updating Your Data
5.
Enter the following code:
<CFQUERY NAME="DeleteEmployee"
</CFQUERY>
<HTML>
<HEAD>
</HEAD>
<BODY>
<H3>The employee record has been deleted.</H3>
</BODY>
</HTML>
6.
Save the page. as
7.
View
The employee is deleted from the Employees table and the message appears.
To delete several records, you would specify a condition. The following example
demonstrates deleting the records for everyone in the Sales department from the
Employee table. The example assumes that there are several Employees in the sales
department.
DELETE FROM Employees
WHERE Department = 'Sales'
To delete all the records from the Employees table, you would use the following:
DELETE FROM Employees
Note
Requiring Users to Enter Values in Form Fields
One of the limitations of HTML forms is the inability to define input fields as required.
Because this is a particularly important requirement for database applications,
ColdFusion provides a server-side mechanism for requiring users to enter data in
fields.
To define an input field as required, use a hidden field that has a NAME attribute
composed of the field name and the suffix "_required." For example, to require that the
user enter a value in the FirstName field, use the syntax:
<INPUT TYPE="hidden" NAME="FirstName_required">
If the user leaves the FirstName field empty, ColdFusion rejects the form submittal and
returns a message informing the user that the field is required. You can customize the
contents of this error message using the VALUE attribute of the hidden field. For
DATASOURCE="CompanyInfo">
DELETE FROM Employees
WHERE Employee_ID = #URL.EmployeeID#
<TITLE>Delete Employee Record</TITLE>
deletepage.cfm
in a browser, enter values, and click the Submit button.
deleteform.cfm
Deleting records from a database is not reversible. Use delete statements
carefully.
.
67
Need help?
Do you have a question about the COLDFUSION 4.5-DEVELOPING WEB and is the answer not in the manual?