You have updated the information for
#Form.FirstName# #Form.LastName#
in the employee database.
</cfoutput>
</body>
</html>
Save the page.
2
View update_form.cfm in your web browser by specifying the page URL and an Employee ID;
3
for example, type the following:
http://localhost/myapps/update_form.cfm?Emp_ID=3.
Enter new values in any of the fields, and click Update Information.
4
ColdFusion updates the record in the Employee table with your new values and displays a
confirmation message.
When the
cfquery
the date with tenths of seconds, as follows:
This example uses the
source connects to company.mdb.
Reviewing the code
The following table describes the highlighted code and its function:
Code
<cfquery name="UpdateEmployee"
datasource="CompanyInfo">
UPDATE Employee
SET FirstName = '#Form.Firstname#',
LastName = '#Form.LastName#',
Dept_ID = #Form.Dept_ID#,
StartDate =
'#left(Form.StartDate,19)#',
Salary = #Form.Salary#
WHERE Emp_ID = #Form.Emp_ID#
</cfquery>
Deleting data
You use a
cfquery
ColdFusion has no
Deleting a single record
To delete a single record, use the table's primary key in the WHERE condition of a SQL
DELETE statement. In the following procedure, Emp_ID is the primary key, so the SQL Delete
statement is as follows:
DELETE FROM Employee WHERE Emp_ID = #Form.Emp_ID#
You often want to see the data before you delete it. The following procedure displays the data to
be deleted by reusing the form page used to insert and update data. Any data that you enter in the
form before submitting it is not used, so you can use a table to display the record to be deleted
instead.
448
Chapter 21: Updating Your Database
tag retrieves date information from a Microsoft Access database, it displays
function to trim the two final characters. The CompanyInfo data
Left
tag with a SQL DELETE statement to delete data from a database.
tag.
cfdelete
Description
Updates the specified columns in the record in
the Employee table of the CompanyInfo
database that matches the primary key (Emp_ID).
Because #Form.Dept_ID#, #Form.Salary#, and
#Form.Emp_ID# are numeric, they do not need
to be enclosed in quotation marks.
Because of the way
cfquery
dates from Access databases, you use the
function to trim the returned value.
gets and displays
Left
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