cf page ignoring cfparam?

Posted on 2012-09-20
Last Modified: 2012-09-20
I have a form on one page, which submits to a second page.

In the form, I have 5 text boxes, named hours1, hours2, hours3, hours4, hours5.

I have this at the top of the second page, to handle blank fields:

<cfparam name="form.hours1"default="0">
<cfparam name="form.hours2" default="0">
<cfparam name="form.hours3" default="0">
<cfparam name="form.hours4" default="0">
<cfparam name="form.hours5" default="0">

Here's my cfquery to insert:

<cfquery name="inserttimeoff" datasource="data">
    VALUES (<cfqueryparam cfsqltype="cf_sql_date" value="#form.DateEntered#">,
    <cfqueryparam cfsqltype="cf_sql_date" value="#form.dayone#">,
    <cfqueryparam cfsqltype="cf_sql_date" value="#form.daytwo#">,
    <cfqueryparam cfsqltype="cf_sql_date" value="#form.daythree#">,
    <cfqueryparam cfsqltype="cf_sql_date" value="#form.dayfour#">,
    <cfqueryparam cfsqltype="cf_sql_date" value="#form.dayfive#">,
    <cfqueryparam cfsqltype="cf_sql_longvarchar" value="#form.comments#">,
    <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.EmployeeID#">,
    <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.ManagerID#">,
    <cfqueryparam value="#form.hours1#" cfsqltype="cf_sql_integer">,
        <cfqueryparam  value="#form.hours2#" cfsqltype="cf_sql_integer">,
            <cfqueryparam value="#form.hours3#" cfsqltype="cf_sql_integer">,
 <cfqueryparam  value="#form.hours4#" cfsqltype="cf_sql_integer">,
<cfqueryparam value="#form.hours5#" cfsqltype="cf_sql_integer">)

I get the following error:

Invalid data '' for CFSQLTYPE CF_SQL_INTEGER.  on line 32 which is:

32 : <cfqueryparam value="#form.hours5#" cfsqltype="cf_sql_integer">)

A CFdump shows this as the values of the hours1-hours5 fields:

HOURS1       8
HOURS2       [empty string]
HOURS3       [empty string]
HOURS4       [empty string]
HOURS5       [empty string]

(I typed in 8, left the rest blank)

So why that error?  Why is the code ignoring the parameters I set in the beginning of the second page?

Need help! Thanks
Question by:Rush_2112
    LVL 51

    Accepted Solution

    cfparam does nothing if the variable you defined already exists. Your fields DO exist, they're just empty.  (Text boxes always exist on the action page). So the cfparam is never called.

    Since an empty string isn't a valid integer either use val() to convert the hour values to 0

        <cfqueryparam value="#VAL(form.hours5)#" cfsqltype="cf_sql_integer">

     -or- pass null when they're empty (if your column allows nulls)

        <cfqueryparam value="#form.hours5#"
                     null="#not IsNumeric(form.hours5)#" cfsqltype="cf_sql_integer">
    LVL 51

    Expert Comment

    ... lather, rinse, repeat for all of the hour fields.
    LVL 1

    Author Comment

    yup, that did it!!  I forgot all about that... thanks!
    LVL 1

    Author Closing Comment


    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math ( While this method is not o…
    I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now