CFINSERT

CFINSERT inserts new records in data sources.

Syntax

<CFINSERT DATASOURCE="ds_name"
    DBTYPE="type"
    DBSERVER="dbms"
    DBNAME="database name"
    TABLENAME="tbl_name"
    TABLEOWNER="owner"
    TABLEQUALIFIER="tbl_qualifier"
    USERNAME="username"
    PASSWORD="password"
    PROVIDER="COMProvider" 
    PROVIDERDSN="datasource" 
    FORMFIELDS="formfield1, formfield2, ...">

DATASOURCE

Required. Name of the data source that contains your table.

DBTYPE

Optional. The database driver type:

DBSERVER

Optional. For native database drivers and the SQLOLEDB provider, specifies the name of the database server machine. 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:

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>