Skip to main content
Inspiring
May 19, 2013
Question

CFQUERYPARAM

  • May 19, 2013
  • 2 replies
  • 753 views

I would like to use user input as CFQUERYPARAM for example,

I have txtMyID on the form and would like to use user input as my query parameter.

I tried to use

  <cfqueryparam value = "#trim(form.txtMyID)#" CFSQLTYPE = "cf_sql_integer">

  but does not work,

 

I tried the following which works, but I need get the value from user enter.

  <CFSET MyID = "1">

  <cfqueryparam value = "#MyID#" CFSQLTYPE = "cf_sql_integer">

Your help and information is great appreciated,

Regards,

Iccsi

    This topic has been closed for replies.

    2 replies

    Inspiring
    May 20, 2013

    The problem is likely with the value of trim(form.txtMyID). Directly using FORM variables is not a good idea, for a variety of reasons. It is better to initialize all your variables as uniquely named local page variables, and then assign values from FORM or other inputs after validating them.

    <cfset ThistxtMyID = "0">

    <cfif IsDefined("FORM.txtMyID") AND IsValid("integer", Trim(FORM.txtMyID)>

        <cfset ThistxtMyID = Trim(FORM.txtMyID)>

    </cfif>

    Be sure to validate ThistxtMyID before you try to use it:

    <cfif ThistxtMyID EQ "0">

    handle this error condition, don't query the database

    </cfif>

    iccsiAuthor
    Inspiring
    May 20, 2013

    Thanks a million for the information and help,

    regards,

    iccsi,

    BreakawayPaul
    Inspiring
    May 19, 2013

    Can you see if cf_sql_numeric works as the type?  I've had problems with integer before.  Also, make sure the data type of your column matches whatever your CFSQLTYPE is.