Groups | Blog | Home
all groups > coldfusion flash integration > february 2006 >

coldfusion flash integration : Inserting data with flash forms



gendrall
2/8/2006 6:34:21 PM
I've been racking my brain for the last 2 days trying to figure out how to do a
simple insert into a database with a Flash form. No matter what I do I can't
get the function to write. I've seen many examples but none work. I've even
tried various code examples in livedocs to stunning error results. Anyway, this
is the code that I'm using on my form:

<cfif IsDefined("form.addInfo") is True>
<!------- Add a resource ------->
<cffunction name="addInfo" output="true" access="public" returntype="boolean"
hint="Add new resources">
<cfargument name="pdf" type="string" required="yes" hint="PDF">
<cfargument name="doc" type="string" required="yes" hint="DOC">
<cfargument name="other" type="string" required="no" hint="other file types">
<cfargument name="Area" type="string" required="yes" hint="Area">
<cfargument name="Category" type="string" required="yes" hint="Category">
<cfargument name="SubCategory" type="string" required="yes" hint="SubCategory">
<cfargument name="ItemNumber" type="string" required="yes" hint="ItemNumber">
<cfargument name="Description" type="string" required="yes" hint="Description">
<cfargument name="modified" type="string" required="yes" hint="modified">


<!------- INSERT INTO THE DEV DATABASE ------->
<cfquery name="Insert" datasource="#ds3#">
INSERT INTO theVaultDev (
pdf,
doc,
other,
Area,
Category,
SubCategory,
ItemNumber,
Description,
modified
)
VALUES (
'#ARGUMENTS.pdf#',
'#ARGUMENTS.doc#',
'#ARGUMENTS.other#',
'#ARGUMENTS.Area#',
'#ARGUMENTS.Category#',
'#ARGUMENTS.SubCategory#',
'#ARGUMENTS.ItemNumber#',
'#ARGUMENTS.Description#',
'1'

)
</cfquery>
<!------- /INSERT INTO THE DEV DATABASE ------->
<cfreturn true>
</cffunction>
</cfif>

What am I doing wrong?
Johnny Derk
2/9/2006 1:29:15 AM
the value 1 being inserted into modified column probably does not need quotes.

gendrall
2/9/2006 2:30:17 PM
hmm...interesting...but I removed the '1' value and a few others and nothing
seems to insert. The reason is for the "modified" is that it's a field in the
database for the updates/inserts to designate what's been modified or what is a
new addition to the "grid".
Johnny Derk
2/9/2006 8:42:00 PM
what values would you be inserting into db. Are some of your values numeric.
Numeric values do not need single quotes.

**Using Quotes** from: http://www.w3schools.com/sql/sql_where.asp
Note that we have used single quotes around the conditional values in the
examples.

SQL uses single quotes around text values (most database systems will also
accept double quotes). Numeric values should not be enclosed in quotes.

For text values:

This is correct:
SELECT * FROM Persons WHERE FirstName='Tove'This is wrong:
SELECT * FROM Persons WHERE FirstName=Tove

For numeric values:

This is correct:
SELECT * FROM Persons WHERE Year>1965This is wrong:
SELECT * FROM Persons WHERE Year>'1965'

gendrall
2/10/2006 5:13:34 PM
The modified field is a yes/no field in the database.

I've not had a problem with this query outside using it in the cffunction.
This is the insert that I used on the current HTML form that the client is
using. So I don't think it's the insert query itself, since I tested outside
the cffunction with no problems and it's being used with no problems on the
HTML form.

It's when I have it in the cffunction that the query insert is ignored.

I wish CF had a "cfgridinsert" function like the cfgridupdate and then I would
not be having this problem :-]
Johnny Derk
2/10/2006 9:07:54 PM
Your question caused me to try my first cfgrid and used it with cfgridupdate- I
was able to insert, delete, and update data with the cfgridupdate tag.

Here was the code I threw together for test purposes:

<!---Cfgrid page---->
<cfquery name="changeinfo" datasource="MyDataSource">
SELECT *
FROM dbo.DBTABLE</cfquery><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<cfform name="insert" action="gridupdat.cfm">
<cfgrid insert="yes" selectmode="edit" delete="yes" query= "changeinfo"
name="change"> </cfgrid>
<cfinput type="submit" name="">
</cfform></body>

Action Page--

<cfgridupdate
grid = "change"
dataSource = "MYDB"
tableName = "MYDBTABLE"
keyonly="yes"
[quoted text, click to view]

Hope this helps
gendrall
2/10/2006 9:32:37 PM
SWEET! That did it.
I didn't have the 'name="insert"' in the cfform tag. Once I put that in there, the form worked.

Awesome.
Thank you thank you thank you! Much appreciate your help.
Johnny Derk
2/10/2006 10:05:21 PM
Thank You for asking the question, because I got to see how incredible cfgrid is. It really is a helpful and powerful tag. I will definately use this in the future
gendrall
2/13/2006 2:43:24 PM
AddThis Social Bookmark Button