MACROMEDIA COLDFUSION 5-DEVELOPING Develop Manual page 130

Table of Contents

Advertisement

110
Reviewing the code
The following table describes the code and its function:
Code
<cfif not
<cfelse>
</cfif>
<cfupdate datasource="CompanyInfo"
<cfoutput>
You have updated the information for
</cfoutput>
Creating an update action page with cfquery
For more complicated updates, you can use a SQL UPDATE statement in a cfquery
tag instead of a
complicated updates.
To create an update page with cfquery:
1
2
isdefined("Form.Contract")>
<cfset Form.contract = "No">
<cfset form.contract = "Yes">
tablename="Employee">
#Form.FirstName# #Form.LastName#
in the Employees database.
cfupdate
Open updatepage.cfm.
Replace the
cfupdate
<cfif not isdefined("Form.Contract")>
<cfset form.contract = "No">
<cfelse>
<cfset form.contract = "Yes">
</cfif>
<cfquery name="UpdateEmployee" datasource="CompanyInfo">
UPDATE Employee
SET FirstName = '#Form.Firstname#',
LastName = '#Form.LastName#',
Dept_ID = '#Form.Dept_ID#',
StartDate = '#Form.StartDate#',
Salary = '#Form.Salary#'
WHERE Emp_ID = #Form.Emp_ID#
</cfquery>
Description
If the user clears the Contractor check box,
no value gets passed to the action page.
Also, the database field must have a value
of Yes or No. Test the Form.contract
variable and set it to No if it is not defined
and Yes if it is defined.
Update the record in the database that
matches the primary key on the form (the
Emp_ID). Update all fields in the record
with names that match the names of
controls on the form.
Inform the user that the change was made
successfully.
tag. The SQL update statement is more flexible for
tag with the highlighted
Chapter 7 Updating Your Database
code.:
cfquery

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COLDFUSION 5-DEVELOPING and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Coldfusion 5

Table of Contents