User Guide

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.