Skip to main content
Participating Frequently
April 8, 2010
Answered

Referencing url variable in cfquery that contains # sign

  • April 8, 2010
  • 2 replies
  • 2564 views

I am using CF 9 and cannot figure out how to reference a url variable in my cfquery that contains a "#" character as part of the string name (i.e. http://somepage.cfm?variable_name=tom#h.

When I try to execute the query, it is only pulling "tom" due to the # sign.  I tried to double up the # sign (##) but that didn't work either.

<cfquery NAME="qryGraph"
DATASOURCE="DB2"
USERNAME=#request.username#
PASSWORD=#request.password#>

SELECT DATE

FROM TABLE
WHERE NAME = '#variable_name#'  

</cfquery>

Any help would be appreciated!

Tom

    This topic has been closed for replies.
    Correct answer ilssac

    How do I make the necessary correction in my code?


    http://somepage.cfm?variable_name=tom%23h.

    And it should work with no other modifications.

    If you are building this code in your CFML you can use the urlEncodedFormat() function.

    2 replies

    ilssac
    Inspiring
    April 8, 2010

    P.S.

    I hope you are planning to use serious SQL injection protections from code like this that uses input from a user via the URL query string.

    ilssac
    Inspiring
    April 8, 2010

    Where did you try to double up the pound sign?

    You may need to use string replacment on your variable to double the pound sign inside the <cfquery...> block.

    Participating Frequently
    April 8, 2010

    I doubled up the pound sign within the url. (i.e. http://somepage.cfm?variable_name=tom##h).  It still only recognized "tom".

    Tom

    ilssac
    Inspiring
    April 8, 2010

    Have you tried something like:

    WHERE Name = '#replace(variable_name,"##","####","ALL")#'

    My feeling is that this rather awkword.... but I'm not sure why your code is not working as it is.