![MACROMEDIA COLDFUSION 5-DEVELOPING Develop Manual Download Page 123](http://html1.mh-extra.com/html/macromedia/coldfusion-5-developing/coldfusion-5-developing_develop-manual_3293641123.webp)
Inserting Data
103
3
Save the file as insertform.cfm in the myapps directory.
4
View insertform.cfm in a browser.
Data entry form notes and considerations
If you use the
cfinsert
tag in the action page to insert the data into the database,
you should follow these rules for creating the form page:
•
You only need to create HTML form fields for the database fields into which you
want to insert data.
•
By default,
cfinsert
inserts all of the form’s fields into the database table fields
with the same names. For example, it puts the Form.Emp_ID value in the
database Emp_ID field. The tag ignores any form fields with no corresponding
database column name. You can also use the
formfields
attribute to specify the
fields you want to insert.
Creating an action page to insert data
You can use the
cfinsert
tag or
cfquery
tag to create an action page that inserts
data into a database.
Creating an insert action page with cfinsert
The
cfinsert
tag is the easiest way to handle simple inserts from either a
cfform
or
an HTML form. This tag inserts data from all the form fields with names that match
database field names.
To create an insert action page with cfinsert:
1
Create a new application page in ColdFusion Studio.
2
Enter the following code:
<!--- Make the contract variable be No if it is not set (check box is
empty) --->
<cfif not isdefined("Form.Contract")>
<cfset Form.contract = "No">
</cfif>
<!--- Insert the new record --->
<cfinsert datasource="CompanyInfo" tablename="Employee">
<html>
<head>
<title>input form</title>
</head>
<body>
<h1>Employee Added</h1>
<cfoutput>You have added #Form.FirstName# #Form.Lastname# to the
employees 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 ...