CFML Reference
|
|
ColdFusion Tags
|
cfinsert
Description
Inserts records in data sources.
Category
Database manipulation tags
Syntax
<cfinsert dataSource = "ds_name"
dbType = "type"
dbServer = "dbms"
dbName = "database name"
tableName = "tbl_name"
connectString = "connection string"
tableOwner = "owner"
tableQualifier = "tbl_qualifier"
username = "username"
password = "password"
provider = "COMProvider"
providerDSN = "datasource"
formFields = "formfield1, formfield2, ...">
See also
cfprocparam,
cfprocresult,
cfquery,
cfqueryparam,
cfstoredproc,
cftransaction,
cfupdate
Attributes
Attribute |
Description |
dataSource
|
Required for all dbType operations except dbType = "dynamic" . Name of the data source that contains your table.
|
dbType
|
Optional. The database driver type:
- dynamic Connect to an ODBC data source that is not defined in the ColdFusion Administrator. When you use this attribute value, you must specify all the ODBC connection information using the
connectstring attribute.
- ODBC (default) ODBC driver.
- Oracle73 Oracle 7.3 native database driver. Using this option, the ColdFusion Server computer must have Oracle 7.3.4.0.0 (or greater) client software installed.
- Oracle80 Oracle 8.0 native database driver. Using this option, the ColdFusion Server computer must have Oracle 8.0 (or greater) client software installed.
- Sybase11 Sybase System 11 native database driver. Using this option, the ColdFusion Server computer must have Sybase 11.1.1 (or greater) client software installed. Sybase patch ebf 7729 is recommended.
- OLEDB OLE DB provider. If specified, this database provider overrides the driver type specified in the ColdFusion Administrator.
- DB2 DB2 5.2 native database driver.
- Informix73 Informix73 native database driver.
|
dbServer
|
Optional. For native database drivers and the SQLOLEDB provider, specifies the name of the database server computer. If specified, dbServer overrides the server specified in the data source.
|
dbName
|
Optional. The database name (Sybase System 11 driver and SQLOLEDB provider only). If specified, dbName overrides the default database specified in the data source.
|
tableName
|
Required. Name of the table you want the form fields inserted in. Note the following:
- ORACLE drivers This specification must be in uppercase.
- Sybase driver This specification is case-sensitive and must be in the same case as that used when the table was created
|
connectString
|
Required for dbType = "dynamic" ; optional for all others. The contents of a connection string to send to the ODBC server. If you are connecting to a data source defined in the ColdFusion Administrator, you can use this attribute to specify additional connection details or to override connection information specified in the Administrator. If you are dynamically connecting to a datasource by specifying dbType = "dynamic" , the connection string must specify all required ODBC connection attributes.
|
tableOwner
|
Optional. For data sources that support table ownership (such as SQL Server, Oracle, and Sybase SQL Anywhere), use this field to specify the owner of the table.
|
tableQualifier
|
Optional. For data sources that support table qualifiers, use this field to specify the qualifier for the table. The purpose of table qualifiers varies across drivers. For SQL Server and Oracle, the qualifier refers to the name of the database that contains the table. For the Intersolv dBase driver, the qualifier refers to the directory where the DBF files are located.
|
username
|
Optional. If specified, username overrides the username value specified in the ODBC setup.
|
password
|
Optional. If specified, password overrides the password value specified in the ODBC setup.
|
provider
|
Optional. COM provider (OLE-DB only).
|
providerDSN
|
Optional. Data source name for the COM provider (OLE-DB only).
|
formFields
|
Optional. A comma-separated list of form fields to insert. If this attribute is not specified, all fields in the form are included in the operation.
|
Example
<!--- This example shows how to use cfinsert instead of cfquery
to place data into a datasource. --->
<!--- if form.POSTED exists, we are inserting a new record,
so begin the cfinsert tag --->
<cfif IsDefined ("form.posted")>
<cfinsert dataSource = "cfsnippets"
tableName = "Comments"
formFields = "Email,FromUser,Subject,MessText,Posted">
<H3><I>Your record was added to the database.</I></H3>
</cfif>
<!--- use a query to show the existing state of the database --->
<cfquery name = "GetComments" dataSource = "cfsnippets">
SELECT CommentID, EMail, FromUser, Subject, CommtType, MessText,
Posted, Processed
FROM Comments
</cfquery>
<html>
<head>
<title>
cfinsert Example
</title>
</head>
<body bgcolor = silver>
<H3>cfinsert Example</H3>
<P>First, we'll show a list of the available comments in the
cfsnippets datasource.
<!--- show all the comments in the db --->
<table>
<TR>
<TD>From User</TD><TD>Subject</TD><TD>Comment Type</TD>
<TD>Message</TD><TD>Date Posted</TD>
</TR>
<cfoutput query = "GetComments">
<TR>
<TD valign = top><a href = "mailto:#Email#">#FromUser#</A></TD>
<TD valign = top>#Subject#</TD>
<TD valign = top>#CommtType#</TD>
<TD valign = top><font size = "-2">#Left(MessText, 125)#
</font></TD>
<TD valign = top>#Posted#</TD>
</TR>
</cfoutput>
</table>
<P>Next, we'll offer the opportunity to enter your own comment:
<!--- make a form for input --->
<form action = "cfinsert.cfm" method = "POST">
<PRE>
Email: <input type = "Text" name = "email">
From: <input type = "Text" name = "fromUser">
Subject:<input type = "Text" name = "subject">
Message:<TEXTAREA name = "MessText" COLS = "40" ROWS = "6"></TEXTAREA>
Date Posted: <cfoutput>#DateFormat(Now())#</cfoutput>
<!--- dynamically determine today's date --->
<input type = "hidden" name = "posted" value = "<cfoutput>#Now()#</cfoutput>">
</PRE>
<input type = "Submit" name = "" value = "insert my comment">
</form>
</body>
</html>
Copyright © 2001, Macromedia Inc. All rights reserved. |
|