MACROMEDIA COLDFUSION MX 61-CFML Reference page 206

Cfml reference
Hide thumbs Also See for COLDFUSION MX 61-CFML:
Table of Contents

Advertisement

Example
<!--- This 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 = "cfsnippets"
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="cfsnippets" tablename="Comments"
formfields="EMail,FromUser,Subject,MessText,Posted">
<cfelse>
<cfinsert datasource="cfsnippets" 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 = "cfsnippets">
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 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 a 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 --->
206
Chapter 2: ColdFusion Tags

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion mx

Table of Contents