View Full Version : ASP help...

09-23-2005, 06:06 PM
I have created a simple shopping cart, but I have run into a problem that is giving me fits. It is for a automotive site. Just a little background first. The database has a table that hold all the part/items. It has fields for part number, name, description, catagory, and price. One the first screen I have created a link column where the user can click on a catagory and it will search the items table for all items that have that catagory listed. Now my problem. When the catagory has a symbol in it, such as "Wheel & Tires" it only searches for Wheel. It works just fine for catagories such as "Pistons" or any catagory with out the symbols. I am passing it info through the querystring.
Currently it is worded as
<a href="page.asp?cat=<% rs("cat") %>">Catagory</a>.

If I us this...
<a href="page.asp?cat= ' <% rs("cat") %> ' ">Catagory</a>

It works fine still for non-symbols but gives a error for "Wheel & Tires".

Any suggestion on how to many symbols such as &?

Thanks in advance.

09-23-2005, 06:24 PM
your issue is that you're passing values through the querystring... & splits values in the querystring... Is there any reason why you have to send it through the querystring like that?
You could replace it with another symbol that you know you wont be using then undo the replace at the other end

09-23-2005, 06:37 PM
Like Nancy pointed out, your query string looks like:

page.asp?cat=Wheel & Tire

which means that when grabbing the value for cat, it will only pick out Wheel and the extra white space after since values are delineated by the = and & signs. Because look at this query string for example:


cat's value is Car and make's value is Mazda. The & sign divides the two in the query string. So your & sign in Wheel & Tire is confusing the program. So you either use another symbol and then replace that symbol with the & sign later on as Nancy suggested or you could just change the & sign to the word "and" instead.


09-23-2005, 07:11 PM
Thanks for the input. I thought the was the case, and that is why I wrapped the script in quotes in my second attempt ( <a href="page.asp?cat=' <% .... %>' " >). I guess I'll use the replace function. I have not used that function before, I guess I'll search for it and read up.

Thanks again.


09-23-2005, 08:24 PM
I would use JavaScript to encode your values for your query string with the function:


Where s is the string you want to url encode. You can also use:


to unencode your encoded data.

09-23-2005, 09:00 PM
Change this: <a href="page.asp?cat=<% rs("cat") %>">Catagory</a>. To this: <a href="page.asp?cat=<% Server.HTMLEncode(rs("cat")) %>">Catagory</a>. That will fix your problem.

09-23-2005, 09:04 PM
If the only problem is the ampersand in the querystring just use Server.URLEncode

<A href='page.asp?cat=<%=Server.URLEncode("my goofy & weird text")%>'>goofy query</a>

09-23-2005, 09:08 PM
Change this: <a href="page.asp?cat=<% rs("cat") %>">Catagory</a>. To this: <a href="page.asp?cat=<% Server.HTMLEncode(rs("cat")) %>">Catagory</a>. That will fix your problem.

htmlencode does nothing to ampersands... I tried that before posting ;)
urlencode might work though, forogot aboutt hat one

09-23-2005, 09:19 PM
If I used <A href='page.asp?cat=<%=Server.URLEncode("my goofy & weird text")%>'>goofy query</a> Would I have to "UN-ENCODE" it on the recieving page?


09-23-2005, 10:31 PM
You guys rock! Thanks for your help!