• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

cfqueryparam insert error

New Here ,
Sep 04, 2008 Sep 04, 2008

Copy link to clipboard

Copied

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!
TOPICS
Advanced techniques

Views

453

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , Sep 04, 2008 Sep 04, 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

Votes

Translate

Translate
Mentor ,
Sep 04, 2008 Sep 04, 2008

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 04, 2008 Sep 04, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 04, 2008 Sep 04, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 04, 2008 Sep 04, 2008

Copy link to clipboard

Copied

LATEST
Gotcha. Thanks to you both for the quick replies.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation