User Guide
cfinsert 253
Example
<!--- This example shows how to use cfinsert instead of cfquery to put
data in a datasource. --->
<!--- If form.POSTED exists, we insert new record, so begin cfinsert tag. --->
<cfif IsDefined ("form.posted")>
<cfinsert dataSource = "cfdocexamples"
tableName = "Comments"
formFields = "Email,FromUser,Subject,MessText,Posted">
<h3><I>Your record was added to the database.</i></h3>
</cfif>
<cfif IsDefined ("form.posted")>
<cfif Server.OS.Name IS "Windows NT">
<cfinsert datasource="cfdocexamples" tablename="Comments"
formfields="EMail,FromUser,Subject,MessText,Posted">
<cfelse>
<cfinsert datasource="cfdocexamples" tablename="Comments"
formfields="CommentID,EMail,FromUser,Subject,MessText,Posted">
</cfif>
<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 = "cfdocexamples">
SELECT
CommentID, EMail, FromUser, Subject, CommtType, MessText, Posted,
Processed
FROM
Comments
</cfquery>
<html>
<head></head>
<h3>cfinsert Example</h3>
<p>First, show a list of the comments in the cfdocexamples 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>
password Optional Overrides password specified in ODBC setup.
formFields Optional (all on
form,
except
keys)
Comma-delimited list of form fields to insert. If not specified,
all fields in the form are included.
If a form field is not matched by a column name in the
database, ColdFusion throws an error.
The database table key field must be present in the form. It
may be hidden.
Attribute Req/Opt Default Description










