Masking the & in a URL variable

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?">
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Renante EnteraSenior PHP DeveloperCommented:
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 :-)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tags266Author Commented:
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#">
Renante EnteraSenior PHP DeveloperCommented:
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 :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.