CFINSERT

CFINSERT inserts new records in data sources.

Syntax

<CFINSERT DATASOURCE="ds_name"
    DBTYPE="type"
    TABLENAME="tbl_name"
    USERNAME="username"
    PASSWORD="password"
    FORMFIELDS="formfield1, formfield2, ...">

DATASOURCE

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

DBTYPE

Optional. The database driver type:

TABLENAME

Required. Name of the table you want the form fields inserted in.

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.

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 add a record 
to the database.
----------------------------------------------------------------------->
<HTML>

<HEAD>
<TITLE>CFINSERT Example</TITLE>
</HEAD>

<CFQUERY NAME="GetMessages" DATASOURCE="CFExpress">
SELECT    Subject, Posted, Message, Message_ID, Thread_ID, Employee_ID
FROM      Messages
</CFQUERY> 


<BODY  bgcolor="#FFFFD5">
<H3>CFINSERT Example</H3>
This is a read-only example. Because database access
is a sensitive area, consider the security of your database before 
allowing people to insert, update, or delete data from it.

<P>First, we'll show a list of the available comments in the cfexpress 
datasource.

<!--- show all the comments in the db --->
<TABLE>
    <TR>
        <TD>Subject</TD><TD>Message</TD><TD>Date Posted</TD>
    </TR>
<CFOUTPUT query="GetMessages">
    <TR>
        <TD valign=top>#Subject#</TD>
        <TD valign=top><FONT SIZE="-2">#Left(Message, 125)#</FONT></TD>
        <TD valign=top>#Posted#</TD>
        <TD valign=top>#Message_ID#</TD>
        <TD valign=top></TD>
    </TR>
<!----------------------------------------------------------------------
Here is where the IDs are incremented so that these values will be 
correct when we insert the new message.
----------------------------------------------------------------------->
<CFSET Thread_ID = Thread_ID + 1>
<CFSET Message_ID = Message_ID + 1>
<CFSET Employee_ID = Employee_ID + 1>    
</CFOUTPUT>
</TABLE>

<!----------------------------------------------------------------------
Take out the comments around this line in order to insert a message into
the messages table.
<CFINSERT datasource="CFExpress" tablename="Messages" >
----------------------------------------------------------------------->

<P>Next, we'll offer the opportunity to enter your own comment:

<!--- make a form for input --->
<FORM ACTION="cfinsert.cfm" METHOD="POST">
<!---------------------------------------------------------------------- 
Dynamically determine today's date. Pass the value of posted, Thread_ID, 
Employee_ID, and Message_ID to CFINSERT by declaring them as Hidden 
inputs.
----------------------------------------------------------------------->
<INPUT TYPE="Hidden" NAME="posted" VALUE="<CFOUTPUT>#Now()#</CFOUTPUT>">
<INPUT TYPE="Hidden" NAME="Thread_ID_float" 
VALUE="<CFOUTPUT>#Thread_ID#</CFOUTPUT>">
<INPUT TYPE="Hidden" NAME="Message_ID_float" 
VALUE="<CFOUTPUT>#Message_ID#</CFOUTPUT>">
<INPUT TYPE="Hidden" NAME="Employee_ID_float"  
VALUE="<CFOUTPUT>#Employee_ID#</CFOUTPUT>">
<P><B>Subject:</B><BR>
<INPUT TYPE="Text" NAME="Subject">
<P><B>Message:</B><BR>
<TEXTAREA NAME="Message" COLS="40" ROWS="6"></TEXTAREA>

Date Posted:    <CFOUTPUT>#DateFormat(Now())#</CFOUTPUT>
</PRE>
<P>
<INPUT TYPE="Submit" VALUE="Insert My Comment">
</FORM> 

</BODY>
</HTML>