Connecting Tech Pros Worldwide Help | Site Map

escaping quotes

  #1  
Old November 11th, 2008, 12:25 PM
Mike P
Guest
 
Posts: n/a
Can anybody tell me what is wrong with this code? I am thinking it is
something to do with how I am escaping the quotes.

<img src="pix2.asp?lbmid=" & Request.QueryString("LBMID") & "&LBMEmail="
& Request.QueryString("LBMEmail") & """ width=1 height=1 border=0>



*** Sent via Developersdex http://www.developersdex.com ***
  #2  
Old November 11th, 2008, 12:55 PM
Bob Barrows [MVP]
Guest
 
Posts: n/a

re: escaping quotes


Mike P wrote:
Quote:
Can anybody tell me what is wrong with this code? I am thinking it is
something to do with how I am escaping the quotes.
>
<img src="pix2.asp?lbmid=" & Request.QueryString("LBMID") &
"&LBMEmail=" & Request.QueryString("LBMEmail") & """ width=1
height=1 border=0>
>
>
>
Two things:
You failed to delineate the server-side code from the client-side html.
Why are you trying to inject a quote there at the end?

Actually 3 things:
You failed to describe your symptoms. At least view the page source after
running the page and show us the resulting img tag, or tell us what the
error message is.

Anyways, the long version:

<img src="pix2.asp?lbmid="
<%Response.Write Request.QueryString("LBMID") %>
&LBMEmail=
<%Response.Write Request.QueryString("LBMEmail") %>
" width=1 height=1 border=0>

The shortcut that most people use:

<img src="pix2.asp?lbmid="<%=Request.QueryString("LBMID ")%>
&LBMEmail=<%=Request.QueryString("LBMEmail")%>" width=1 height=1 border=0>

The idea is to write the html the way it should look with hard-coded values:

<img src="pix2.asp?lbmid=12345&LBMEmail=me@abc.com" width=1 height=1
border=0>

Then replace the hard-coded values with the server-side script blocks. There
is no need to do the concatenation inside the server-script blocks. Yes, you
could have done this:

<img src="pix2.asp?lbmid="<%=Request.QueryString("LBMID ") & "&LBMEmail=" &
Request.QueryString("LBMEmail")%>" width=1 height=1 border=0>

but it can get confusing and there really is no need to do this unless you
are making decisions in the server-side code as to what name-value pairs are
being included in the querystring.

--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
escaping quotes in a mysql insert statment alanv answers 1 April 1st, 2008 03:21 AM
Escaping quotes withing quotes duwayne@gmail.com answers 7 July 23rd, 2005 08:52 PM
Escaping quotes for innerHTML in Mozilla Ted Weatherly answers 1 July 20th, 2005 03:58 PM
php escaping quotes mudassar answers 1 July 17th, 2005 02:35 AM