<html>
<head>
<link href="mmres://user_interface_reference.css" rel="stylesheet" type="text/css">
<title>CFINSERT</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
   <div id="Description">
   <table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
      <tr> 
         <td valign="top" class="name">CFINSERT</td>
         <td valign="top" nowrap class="compatibility">&nbsp;</td>
      </tr>
      <tr>
         <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
      </tr>


    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Description</span>
<p>
Inserts records in data sources from data in a ColdFusion form or form Scope. 
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Category</span>
<p>
Database manipulation tags
</p>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="syntax"><span class="title">Syntax</span><pre>&lt;cfinsert 
   dataSource = &quot;ds_name&quot;
   tableName = &quot;tbl_name&quot;
   tableOwner = &quot;owner&quot;
   tableQualifier = &quot;tbl_qualifier&quot;
   username = &quot;username&quot;
   password = &quot;password&quot;
   formFields = &quot;formfield1, formfield2, ...&quot;&gt;
</pre>    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">See also</span>
<p>
cfprocparam, cfprocresult, cfquery, cfqueryparam, cfstoredproc, cftransaction, cfupdate
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">History</span>
<p>
ColdFusion&#160;MX: Deprecated the connectString, dbName, dbServer, dbtype, provider, and providerDSN attributes. They do not work, and might cause an error, in releases later than ColdFusion 5. 
</p>

<p>

</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Example</span><pre>&lt;!--- This example shows how to use cfinsert instead of cfquery to put 
data in a datasource. ---&gt;
&lt;!--- If form.POSTED exists, we insert new record, so begin cfinsert tag. ---&gt;
&lt;cfif IsDefined (&quot;form.posted&quot;)&gt;
   &lt;cfinsert dataSource = &quot;cfdocexamples&quot;
      tableName = &quot;Comments&quot;
      formFields = &quot;Email,FromUser,Subject,MessText,Posted&quot;&gt;
   &lt;h3&gt;&lt;I&gt;Your record was added to the database.&lt;/i&gt;&lt;/h3&gt;
&lt;/cfif&gt;

&lt;cfif IsDefined (&quot;form.posted&quot;)&gt; 
   &lt;cfif Server.OS.Name IS &quot;Windows NT&quot;&gt; 
      &lt;cfinsert datasource=&quot;cfdocexamples&quot; tablename=&quot;Comments&quot;
         formfields=&quot;EMail,FromUser,Subject,MessText,Posted&quot;&gt; 
   &lt;cfelse&gt; 
      &lt;cfinsert datasource=&quot;cfdocexamples&quot; tablename=&quot;Comments&quot;
         formfields=&quot;CommentID,EMail,FromUser,Subject,MessText,Posted&quot;&gt; 
   &lt;/cfif&gt; 
   &lt;h3&gt;&lt;i&gt;Your record was added to the database.&lt;/i&gt;&lt;/h3&gt; &lt;/cfif&gt; 

&lt;!--- Use a query to show the existing state of the database. ---&gt;
&lt;cfquery name = &quot;GetComments&quot; dataSource = &quot;cfdocexamples&quot;&gt;
   SELECT 
      CommentID, EMail, FromUser, Subject, CommtType, MessText, Posted, 
Processed
   FROM 
      Comments
&lt;/cfquery&gt;

&lt;html&gt;
&lt;head&gt;&lt;/head&gt;
&lt;h3&gt;cfinsert Example&lt;/h3&gt;
&lt;p&gt;First, show a list of the comments in the cfdocexamples datasource.
&lt;!--- show all the comments in the db ---&gt;
&lt;table&gt;
   &lt;tr&gt;
      &lt;td&gt;From User&lt;/td&gt;&lt;td&gt;Subject&lt;/td&gt;&lt;td&gt;Comment Type&lt;/td&gt;
      &lt;td&gt;Message&lt;/td&gt;&lt;td&gt;Date Posted&lt;/td&gt;
   &lt;/tr&gt;
   &lt;cfoutput query = &quot;GetComments&quot;&gt;
      &lt;tr&gt;
         &lt;td valign = top&gt;&lt;a href = &quot;mailto:#Email#&quot;&gt;#FromUser#&lt;/A&gt;&lt;/td&gt;
         &lt;td valign = top&gt;#Subject#&lt;/td&gt;
         &lt;td valign = top&gt;#CommtType#&lt;/td&gt;
         &lt;td valign = top&gt;&lt;font size = &quot;-2&quot;&gt;#Left(MessText, 125)#&lt;/font&gt;&lt;/td&gt;
         &lt;td valign = top&gt;#Posted#&lt;/td&gt;
      &lt;/tr&gt;
   &lt;/cfoutput&gt;
&lt;/table&gt;
&lt;p&gt;Next, we'll offer the opportunity to enter a comment:
&lt;!--- make a form for input ---&gt;
&lt;form action = &quot;cfinsert.cfm&quot; method = &quot;post&quot;&gt;
   &lt;pre&gt;
   Email:    &lt;input type = &quot;Text&quot; name = &quot;email&quot;&gt;
   From:    &lt;input type = &quot;Text&quot; name = &quot;fromUser&quot;&gt;
   Subject:&lt;input type = &quot;Text&quot; name = &quot;subject&quot;&gt;
   Message:&lt;textarea name = &quot;MessText&quot; COLS = &quot;40&quot; ROWS = &quot;6&quot;&gt;&lt;/textarea&gt;
   Date Posted:    &lt;cfoutput&gt;#DateFormat(Now())#&lt;/cfoutput&gt;
   &lt;!--- dynamically determine today's date ---&gt;
   &lt;input type = &quot;hidden&quot; 
      name = &quot;posted&quot; value = &quot;&lt;cfoutput&gt;#Now()#&lt;/cfoutput&gt;&quot;&gt;
   &lt;/pre&gt;
   &lt;input type = &quot;Submit&quot; 
      name = &quot;&quot; value = &quot;insert my comment&quot;&gt;
&lt;/form&gt;
</pre>
         </td>
      </tr>
   </table>
   </div>
<div id="DATASOURCE">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">DATASOURCE</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>

  <tr>
  <td valign="top" class="syntax">&nbsp;</td>
  <td valign="top" nowrap class="requirements">Required </td>
  </tr>
  <tr>
  <td colspan="2" class="clearseparation">&nbsp;</td>
  </tr>
  <tr>
  <td valign="top" colspan="2" class="description">



<p>Data source; contains table.</p>

  </td>
  </tr>
  </table>
</div>
<div id="TABLENAME">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">TABLENAME</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>

  <tr>
  <td valign="top" class="syntax">&nbsp;</td>
  <td valign="top" nowrap class="requirements">Required</td>
  </tr>
  <tr>
  <td colspan="2" class="clearseparation">&nbsp;</td>
  </tr>
  <tr>
  <td valign="top" colspan="2" class="description">



<p>Table in which to insert form fields.</p>
<p>ORACLE drivers: must be uppercase.</p>
<p>Sybase driver: case-sensitive. Must be the same case used when table was created</p>

  </td>
  </tr>
  </table>
</div>
<div id="TABLEOWNER">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">TABLEOWNER</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>

  <tr>
  <td valign="top" class="syntax">&nbsp;</td>
  <td valign="top" nowrap class="requirements">Optional</td>
  </tr>
  <tr>
  <td colspan="2" class="clearseparation">&nbsp;</td>
  </tr>
  <tr>
  <td valign="top" colspan="2" class="description">



<p>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.</p>

  </td>
  </tr>
  </table>
</div>
<div id="TABLEQUALIFIER">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">TABLEQUALIFIER</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>

  <tr>
  <td valign="top" class="syntax">&nbsp;</td>
  <td valign="top" nowrap class="requirements">Optional</td>
  </tr>
  <tr>
  <td colspan="2" class="clearseparation">&nbsp;</td>
  </tr>
  <tr>
  <td valign="top" colspan="2" class="description">



<p>For data sources that support table qualifiers, use this field to specify qualifier for table. The purpose of table qualifiers varies among drivers. For SQL Server and Oracle, qualifier refers to name of database that contains table. For Intersolv dBASE driver, qualifier refers to directory where DBF files are located.</p>

  </td>
  </tr>
  </table>
</div>
<div id="USERNAME">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">USERNAME</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>

  <tr>
  <td valign="top" class="syntax">&nbsp;</td>
  <td valign="top" nowrap class="requirements">Optional</td>
  </tr>
  <tr>
  <td colspan="2" class="clearseparation">&nbsp;</td>
  </tr>
  <tr>
  <td valign="top" colspan="2" class="description">



<p>Overrides username specified in ODBC setup.</p>

  </td>
  </tr>
  </table>
</div>
<div id="PASSWORD">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">PASSWORD</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>

  <tr>
  <td valign="top" class="syntax">&nbsp;</td>
  <td valign="top" nowrap class="requirements">Optional</td>
  </tr>
  <tr>
  <td colspan="2" class="clearseparation">&nbsp;</td>
  </tr>
  <tr>
  <td valign="top" colspan="2" class="description">



<p>Overrides password specified in ODBC setup.</p>

  </td>
  </tr>
  </table>
</div>
<div id="FORMFIELDS">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">FORMFIELDS</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>

  <tr>
  <td valign="top" class="syntax">&nbsp;</td>
  <td valign="top" nowrap class="requirements">Optional</td>
  </tr>
  <tr>
  <td colspan="2" class="clearseparation">&nbsp;</td>
  </tr>
  <tr>
  <td valign="top" colspan="2" class="description">

<strong>Default value:</strong> "(all on form, except keys)"


<p>Comma-delimited list of form fields to insert. If not specified, all fields in the form are included.</p>
<p>If a form field is not matched by a column name in the database, ColdFusion throws an error. </p>
<p>The database table key field must be present in the form. It may be hidden.</p>

  </td>
  </tr>
  </table>
</div>

  </body>
</html>
