Adobe COLDFUSION 9 Manual page 426

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Accessing and Using Data
The following procedure assumes that you have created the insert_action.cfm page, as described in
action page with
cfinsert" on page 419.
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="cfdocexamples">
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.
</cfoutput>
</body>
</html>
Save the page.
2
View insert_form.cfm in your web browser and enter values.
3
4
Click Submit.
ColdFusion inserts your values into the Employee table and displays a confirmation message.
Reviewing the code
The following table describes the highlighted code and its function:
Code
<cfquery name="AddEmployee"
datasource="cfdocexamples">
INSERT INTO Employee VALUES
(#Form.Emp_ID#,
'#Form.FirstName#',
'#Form.LastName#',
#Form.Dept_ID#,
'#Form.StartDate#',
#Form.Salary#, '#Form.Contract#')
</cfquery>
tag with the following highlighted
cfinsert
Description
Inserts a new row into the Employee table of the cfdocexamples database. Specifies each form
field to be added.
Because you are inserting data into all database fields in the same left-to-right order as in the
database, you do not have to specify the database field names in the query.
Because
#From.Emp_ID#
,
#Form.Dept_ID#
not need to be enclosed in quotation marks.
Last updated 8/5/2010
"Creating an insert
code:
cfquery
, and
#Form.Salary#
are numeric, they do
421

Advertisement

Table of Contents
loading

Table of Contents