Link to home
Start Free TrialLog in
Avatar of bjrcreations
bjrcreations

asked on

Request.QueryString translates plus sign into a space?!?!

My first page contains an e-mail address from a database and an edit link. The edit link takes you to the edit page with a single text field containing the e-mail address. I get that e-mail from the previous page by passing it into the URL - "www.myurl.com?edit=somename@someurl.com" and then I use Request.QueryString. The problem is that some valid e-mail addresses contain a plus sign in the name. That plus sign is translated into a space when it appears in the text field. Any suggestions?
ASKER CERTIFIED SOLUTION
Avatar of ASPGuru
ASPGuru

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
email = "some+name@someurl.com"
editlink = "www.myurl.com?edit=" & Server.URLEncode(email)

on the second page, you may be wondering how to "UN Urlencode" that variable. To do so, put in your asp page, at the bottom or wherever, the following function:

%>
<script language=JavaScript RUNAT=SERVER>
// This function decodes the any string
// that's been encoded using URL encoding technique
function URLDecode(psEncodeString)
{
  // Create a regular expression to search all +s in the string
  var lsRegExp = /\+/g;
  // Return the decoded string
  return unescape(String(psEncodeString).replace(lsRegExp, " "));
}
</script>
<%

Note, that is NOT within the <%%>.

You can then, from anywhere in the ASP code, make a call like:

Response.Write URLDecode(Request.Querystring("edit"))
Avatar of ASPGuru
ASPGuru

LOOM, what are you talking about??
Querystring gets decoded automatically by ASP, when received through the querystring... no need to decode it manually...

ASPGuru
ASPGuru,
 My bad! You are correct. I use Server.URLEncode quite a bit to store data into databases. So, when I retrieve the data, I use the above function to decode the data. Works great, and you don't have to worry about invalid characters in the data, such as an unexpected single quote.

bjrcreations,
 Sorry about that.
Avatar of bjrcreations

ASKER

Thanks ASPGuru - that was exactly what I needed!
@LOOM
a single quote isn't invalid... you just need to escape it with a second single quote...

name="O'Mealey"
name=replace(name,"'","''")

sql="select * from tab where name='" & name & "'"


ASPGUru
Unless you are using MySQL, in which case you have to escape it with a '\'. So, to make it compatible with all DB's, I just use the URLEncode.
i usually use a function which looks like this:

function sqlText(t)
  sqlText = replace(t,"'","''")
end function

then you just need to replace at one place...

ASPGuru
I have a similar function as well. Anyway, we're off topic and trading knowledge we both know about. CIAO for now.