Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
Thanks a million for the information and help,
regards,
iccsi,