Masking the & in a URL variable

Posted on 2006-03-21
Last Modified: 2013-12-24
My code is of the records that shows up in my URL variable is the cable network A&E.  However the '&' is screwing up my search queries in my URL variable for 'networks'.  I'm sure this is an easy fix but if someone can point me in the right direction I'd be grateful.  Thanks

<cfif isdefined("form.submit") and form.submit EQ "Search Units">
<cflocation url="unit_search_results.cfm?">
Question by:tags266
    LVL 14

    Accepted Solution

    Hi tags266!

    In this case, you will have to use CF functions URLEncodedFormat() and URLDecode() to resolve your problem.

    For your reference, simply visit the following :
      URLEncodedFormat -
      URLDecode -

    So, the code will be like this :
    <!--- use URLEncodedFormat() first before sending it as value of you url parameters --->
    <cfif isdefined("form.submit") and form.submit EQ "Search Units">
      <cfset newCity = URLEncodedFormat(>
      <cfset newSubregion = URLEncodedFormat(form.subregion)>
      <cfset newNetwork = URLEncodedFormat(>
      <cfset newTimeslot = URLEncodedFormat(form.timeslot)>

      <cflocation url="unit_search_results.cfm?city=#newCity#&subregion=#newSubregion#&network=#newNetwork#&timeslot=#newTimeslot#">

    Then, on your "unit_search_results.cfm" :
    <!--- use URLDecode() first before using its value as condition(s) on your query statement --->
      <cfset newCity = URLDecode(url.newCity )>
      <cfset newSubregion = URLDecode(url.newSubregion )>
      <cfset newNetwork = URLDecode(url.newNetwork )>
      <cfset newTimeslot = URLDecode(url.newTimeslot )>

      <!--- Then your query statement will follow ... --->

    I hope that this helps you.  Just try it.

    eNTRANCE2002 :-)

    Author Comment

    Thanks entrance..that's it.  sorry for the late points...i've increased them for you...just one thing was wrong with your <cflocation url which was confusing me...

    This is what you wrote:
    cflocation url="unit_search_results.cfm?city=#newCity#&subregion=#newSubregion#&network=#newNetwork#&timeslot=#newTimeslot#">

    It should be:
    cflocation url="unit_search_results.cfm?newcity=#newCity#&newsubregion=#newSubregion#&newnetwork=#newNetwork#&newtimeslot=#newTimeslot#">
    LVL 14

    Expert Comment

    by:Renante Entera
    Hi tags266!

    I apologize for that minor mistake.  Anyway, I'm glad that you've seen it.

    BTW, thanks for the points and grade. I'm glad that I have helped you.  Hope to help you again...

    eNTRANCE2002 :-)

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Suggested Solutions

    If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
    Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    754 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

    17 Experts available now in Live!

    Get 1:1 Help Now