104
Chapter 7 Updating Your Database
</cfoutput>
</body>
</html>
3
Save the page as insertaction.cfm.
4
View insertform.cfm in a browser, enter values, and click the Submit button.
5
The data is inserted into the Employee table and the message displays.
Reviewing the code
The following table describes the code and its function:
Note
If you use form variables in
cfinsert
or
cfupdate
tags, ColdFusion automatically
validates any form data it sends to numeric, date, or time data database columns.
You can use the hidden field validation functions for these fields to display a custom
error message.
Code
Description
<cfif not isdefined("Form.Contract")>
<cfset Form.contract = "No">
</cfif>
If the user clears the Contractor check
box, no value gets passed to the action
page. The database field must have a
value, so check the Form.contract
variable and set it to No if it is not
defined.
<cfinsert datasource="CompanyInfo"
tablename="Employee">
Create a new row in the Employee table
of the CompanyInfo database. Insert
data from the form into database fields
with the same names as the form fields.
<cfoutput>You have added
#Form.FirstName# #Form.Lastname#
to the employees database.
</cfoutput>
Inform the user that the data was
inserted into the database.
Summary of Contents for COLDFUSION 5-DEVELOPING
Page 1: ...Macromedia Incorporated Developing ColdFusion Applications MacroMedia ColdFusion 5 ...
Page 58: ...38 Chapter 3 Querying a Database ...
Page 134: ...114 Chapter 7 Updating Your Database ...
Page 210: ...190 Chapter 10 Reusing Code ...
Page 232: ...212 Chapter 11 Preventing and Handling Errors ...
Page 238: ...218 Chapter 12 Using the Application Framework ...
Page 262: ...242 Chapter 12 Using the Application Framework ...
Page 278: ...258 Chapter 13 Extending ColdFusion Pages with CFML Scripting ...
Page 320: ...300 Chapter 15 Indexing and Searching Data ...
Page 336: ...316 Chapter 16 Sending and Receiving E mail ...
Page 374: ...354 Chapter 18 Interacting with Remote Servers ...