One way I've dealt with this is to create 2 variables lcInsertList and
lcInsertValues.  Basically my code looks like:

<cfset lcInsertList = "">
<cfset lcInsertValues = "">

<cfif LEN(TRIM(form.Var1)) NEQ 0>
    <cfset lcInsertList = lcInsertList & "FILENAME,">
    <cfset lcInsertValues = lcInsertValues & "'" & form.Var1 & "',">
</cfif>

<cfif LEN(TRIM(form.Var2)) NEQ 0>
    <cfset lcInsertList = lcInsertList & "DIM,">
    <cfset lcInsertValues = lcInsertValues & form.Var2 & ",">
</cfif>

<cfif LEN(TRIM(form.Var3)) NEQ 0>
    <cfset lcInsertList = lcInsertList & "CONFIG,">
    <cfset lcInsertValues = lcInsertValues & "'" & form.Var3 & "',">
</cfif>

<cfquery ....>
    INSERT INTO products 
        (#LEFT(lcInsertList, LEN(lcInsertList) - 1)#) 
        VALUES (#LEFT(lcInsertValues, LEN(lcInsertValues) - 1)#)
</cfquery>

Bill Grover
Supervisor, IS
EU Services, Inc.
649 N Horners Ln
Rockville MD 20850

Phone: 301-424-3300 x396
FAX:    301-424-3300 x1396#
E-Mail: [EMAIL PROTECTED]


> -----Original Message-----
> From: Chad Gray [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, November 13, 2001 7:32 PM
> To: CF-Talk
> Subject: RE: SQL INSERT
> 
> 
> If the text input is left blank on the form then when it is 
> passed to the 
> action page is has a value of ""
> 
> Since it has a value the <cfparam> is not kicking in.  I 
> would have to 
> write logic like Bryan mentioned.
> 
> <cfif form.numberVar3 IS ""><cfset form.numberVar3 = "NULL"></cfif>
> 
> none of the radio buttons or check boxes are numbers.  They are text.
> 
> 
> 
> At 01:20 PM 11/14/2001 +1300, you wrote:
> >so you're saying when you don't select a checkbox then it's 
> setting the var
> >to "" ?
> >
> >-----Original Message-----
> >From: Chad Gray [mailto:[EMAIL PROTECTED]]
> >Sent: Wednesday, 14 November 2001 1:19 p.m.
> >To: CF-Talk
> >Subject: RE: SQL INSERT
> >
> >
> >So such luck.  Since the form is defining the var to "" the 
> <cfparam ...
> >default="0"> is not taking effect.
> >
> >Guess i will just have to write the <CFIF> logic that Bryan 
> was talking
> >about.  This sucks since i have about 30 inputs to check.
> >
> >Thanks everyone!
> >
> >
> >
> >At 07:11 PM 11/13/2001 -0500, you wrote:
> > >Some of them are.... i will try this.  Thanks.
> > >
> > >At 01:03 PM 11/14/2001 +1300, you wrote:
> > > >The fields that you're inserting into wouldn't happen to 
> be number fields
> > > >would they?
> > > >
> > > >if so you might want to do <cfparam name="form.var" default="0">
> > > >
> > > >-----Original Message-----
> > > >From: Chad Gray [mailto:[EMAIL PROTECTED]]
> > > >Sent: Wednesday, 14 November 2001 12:50 p.m.
> > > >To: CF-Talk
> > > >Subject: SQL INSERT
> > > >
> > > >
> > > >This seems like such a beginner question, but can you 
> use INSERT INTO
> >with
> > > >form fields that are left blank?  ( i am using <cfparam 
> name="form.var"
> > > >default=""> for the radio buttons, and check boxes on 
> the action page )
> > > >
> > > >Im getting a "Syntax error in INSERT INTO statement".  
> THe statement
> >works
> > > >fine if all the fields in the form are filled out.  If i 
> submit the form
> > > >with all blanks i get this error.
> > > >
> > > >The resulting SQL statement looks something like this on 
> the action page:
> > > >
> > > >SQL =
> > > >INSERT INTO products (FILENAME,DIM,CONFIG)
> > > >VALUES ('',,'')
> > > >
> > > >This is with a MS Access database also.
> > > >
> > > >DO i have to have to do:
> > > >INSERT INTO products (<CFIF form.var is not "">FILENAME</CFIF>)
> > > >VALUES (<CFIF form.var is not "">#form.filename#</CFIF>)
> > > >
> > > >I hope not!
> > > >
> > > >
> > > >
> > > >
> > > >
> > >
> >
> >
> 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Get the mailserver that powers this list at http://www.coolfusion.com
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to