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

Using CFquery to insert

New Here ,
Feb 09, 2007 Feb 09, 2007

Copy link to clipboard

Copied

Hello,

I am using CFquery to insert data from a form into an Access database. If all fields are not entered a message is returned indicating that "Element X is undefined in FORM." The Access database fields allow null values. If I entered data into every field it works fine. I have tried using cfqueryparam to check for null but have had no luck. My code is below. Any help is greatly appreciated.

INSERT INTO ISDSUserSurvey
(1)
VALUES <cfqueryparam value="#trim(form.1)#" cfsqltype="CF_SQL_VARCHAR" null="#YesNoFormat(not(len(trim(form.1))))#"/>

and this code:

INSERT INTO ISDSUserSurvey
(1)
VALUES (<cfif IsDefined("#Form.1#") AND "#Form.1#" NEQ "">
'#Form.1#',
<cfelse>
NULL,
</cfif>
TOPICS
Advanced techniques

Views

336

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 ,
Feb 09, 2007 Feb 09, 2007

Copy link to clipboard

Copied

On your form, what type of element is form1?

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 ,
Feb 09, 2007 Feb 09, 2007

Copy link to clipboard

Copied

Hello, the input type is radio button with three options.

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 ,
Feb 09, 2007 Feb 09, 2007

Copy link to clipboard

Copied

If nothing is selected, your variable won't be defined. That's why your cfqueryparam didn't work. Your approach only works when the input is a text box or drop down,

Your 2nd attempt failed because "#Form.1#" is a string, it is not outputting a variable. The simplest thing is to get rid of 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
New Here ,
Feb 09, 2007 Feb 09, 2007

Copy link to clipboard

Copied

Great thanks!

Do you have a method that will work for radio buttons, check boxes, and text fields?

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 ,
Feb 09, 2007 Feb 09, 2007

Copy link to clipboard

Copied

LATEST
the cfparam tag may be helpful. details are in the cfml reference manual. If you don't have one, the internet does.

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