Chapter 6: Updating Your Data
67
5.
Enter the following code:
<CFQUERY NAME="DeleteEmployee"
DATASOURCE="CompanyInfo">
DELETE FROM Employees
WHERE Employee_ID = #URL.EmployeeID#
</CFQUERY>
<HTML>
<HEAD>
<TITLE>Delete Employee Record</TITLE>
</HEAD>
<BODY>
<H3>The employee record has been deleted.</H3>
</BODY>
</HTML>
6.
Save the page. as
deletepage.cfm
.
7.
View
deleteform.cfm
in a browser, enter values, and click the Submit button.
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
Deleting records from a database is not reversible. Use delete statements
carefully.
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
Summary of Contents for COLDFUSION 4.5-DEVELOPING WEB
Page 1: ...Allaire Corporation Developing Web Applications with ColdFusion ColdFusion 4 5...
Page 14: ...xiv Developing Web Applications with ColdFusion...
Page 26: ...xxvi Developing Web Applications with ColdFusion...
Page 34: ...8 Developing Web Applications with ColdFusion...
Page 70: ...44 Developing Web Applications with ColdFusion...
Page 84: ...58 Developing Web Applications with ColdFusion...
Page 114: ...88 Developing Web Applications with ColdFusion...
Page 148: ...122 Developing Web Applications with ColdFusion...
Page 174: ...148 Developing Web Applications with ColdFusion...
Page 208: ...182 Developing Web Applications with ColdFusion...
Page 244: ...218 Developing Web Applications with ColdFusion...
Page 274: ...248 Developing Web Applications with ColdFusion...
Page 288: ...262 Developing Web Applications with ColdFusion...
Page 300: ...274 Developing Web Applications with ColdFusion...
Page 350: ...324 Developing Web Applications with ColdFusion...
Page 362: ...336 Developing Web Applications with ColdFusion...