• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 406
  • Last Modified:

cf page ignoring cfparam?

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">
INSERT INTO timeoff
(DateEntered,dayone,daytwo,daythree,dayfour,dayfive,comments,EmployeeID,ManagerID,hours1,hours2,hours3,hours4,hours5)
    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">)
 </cfquery>

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
0
Rush_2112
Asked:
Rush_2112
  • 2
  • 2
1 Solution
 
_agx_Commented:
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">
0
 
_agx_Commented:
... lather, rinse, repeat for all of the hour fields.
0
 
Rush_2112Author Commented:
yup, that did it!!  I forgot all about that... thanks!
0
 
Rush_2112Author Commented:
perfect!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now