Skip to main content
Participant
September 4, 2008
Answered

cfqueryparam insert error

  • September 4, 2008
  • 4 replies
  • 544 views
I'm trying to update an INSERT query statement with <cfqueryparam>s and am getting an error.

It worked fine before, and when I only ad the cfqp to the "WHERE" statement, but when I mix cfqp into even one "SET" item, it throws an error.

What am I doing wrong??

Thanks!
This topic has been closed for replies.
Correct answer paross1
For starters, stop enclosing your CFQUERYPARAM tags within single quotes.

'<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#Form.FirstName#" />' is not necessary...

use <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#Form.FirstName#">

Phil

4 replies

pja5362Author
Participant
September 4, 2008
Gotcha. Thanks to you both for the quick replies.
Inspiring
September 4, 2008
If Cold Fusion gives you an empty string, and the datatype is text, you can make the field null or an empty string. Your choice.

If it's numeric or date, you have to make it null or you'll have a data type mismatch.

The way I do it is to set some variable to either true or false before the query, and set the cfqueryparam null attribute to that variable.
pja5362Author
Participant
September 4, 2008
Fantastic! That did the trick! Thanks!!

I retained all instances of wrapping string-based query variables in single quotes when i updated the site with cfqp's, and am only getting errors when trying to write to the database. should i get rid of them all, even in simple "SELECT" queries?

Also, should i add the null parameter to all the items in my queries that write to the db? For example:

<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#Form.FirstName#" null="#YesNoFormat(Len(Trim(Form.FirstName)))#">

I came across the null variable for the first time this morning and don't know anything about it.
paross1Correct answer
Participating Frequently
September 4, 2008
For starters, stop enclosing your CFQUERYPARAM tags within single quotes.

'<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#Form.FirstName#" />' is not necessary...

use <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#Form.FirstName#">

Phil