MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual page 441

Developing coldfusion mx applications
Table of Contents

Advertisement

Reviewing the code
The following table describes the code and its function:
Code
<cfif not isdefined("Form.Contract")>
<cfset Form.Contract = "No">
</cfif>
<cfinsert datasource="CompanyInfo"
tablename="Employee">
<cfoutput>You have added
#Form.FirstName# #Form.Lastname#
to the employee database.
</cfoutput>
Note: If you use form variables in
any form data it sends to numeric, date, or time database columns. You can use the hidden field
validation functions for these fields to display a custom error message. For more information, see
Chapter 26, "Retrieving and Formatting Data," on page
Creating an insert action page with cfquery
For more complex inserts from a form submittal, you can use a SQL INSERT statement in a
tag instead of using a
cfquery
because you can insert information selectively or use functions within the statement.
The following procedure assumes that you have created the insert_action.cfm page, as described
in
"Creating an insert action page with cfinsert" on page
To create an insert action page with cfquery:
In insert_action.cfm, replace the
1
<html>
<head>
<title>Input form</title>
</head>
<body>
<!--- If the Contractor check box is clear),
set the value of the Form.Contract to "No" --->
<cfif not isdefined("Form.Contract")>
<cfset Form.Contract = "No">
</cfif>
<!--- Insert the new record --->
<cfquery name="AddEmployee" datasource="CompanyInfo">
INSERT INTO Employee
VALUES (#Form.Emp_ID#, '#Form.FirstName#',
'#Form.LastName#', #Form.Dept_ID#,
'#Form.StartDate#', #Form.Salary#, '#Form.Contract#')
</cfquery>
<h1>Employee Added</h1>
<cfoutput>You have added #Form.FirstName# #Form.Lastname# to the
employee database.
Description
Sets the value of Form.Contract to No if it is not
defined. If the Contractor check box is unchecked,
no value is passed to the action page; however, the
database field must have some value.
Creates a new row in the Employee table of the
CompanyInfo database. Inserts data from the form
into the database fields with the same names as the
form fields.
Informs the user that values were inserted into the
database.
cfinsert
or
cfupdate
tag. The SQL INSERT statement is more flexible
cfinsert
tag with the following highlighted
cfinsert
tags, ColdFusion automatically validates
559.
440.
code:
cfquery
Inserting data
441

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion mx

Table of Contents