SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast hombre_de_las_ca's Avatar
    Join Date
    Apr 2005
    Location
    Bangalore, India
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation how to append words with characters like &, ?, " to the url while passing a variable

    hi guys and gals
    well i just came across a very perplexing problem with my web application...
    i created a database based web application using Asp and MS Access for a company's inventory and maintenence requirements. every thing worked fine untill the name for a perticular vendor for a part contained in the inventory was entered.
    Vendor Name : L&T

    The Problem:
    passed url with the name appended as .../file.asp?Vname=L&T

    Result:
    the page file.asp opened with a url :
    .../file.asp?Vname=L

    i.e > &T went missing.
    and as a consiquence the database was sent a query containing of only T and not L&T
    and so the result upon objrs.Update gave an error (quiet obvious as there was no record with the name T).
    same happened when they tried to enter a part name as DRILL BIT 1/2" ie 1/2 inch and the same problem came up with ".

    what i found by observing google was that they would replace & with %26 and space with %21...etc....and go about it with out any errors....but i have no idea of doing it on my application

    and one more thing....the url is created when the script is executed on the server by retreving the name and appending it to a url link on the page.

    it would be appreciated if the response is a bit detailed in giving the solution or atleast a direction to it...



    hombre_de_las_cavernas
    Don't ask what your Country can do for you,
    Ask what you can do for your Country.

  2. #2
    Original Gangster silver trophy Thing's Avatar
    Join Date
    Oct 2000
    Location
    Philadelphia, PA
    Posts
    4,708
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    When you pull the querystring into your script you can replace the %26 with a & like so:

    Code:
    varVendor = REPLACE(request.querystring("Vname"), "%26", "&")

  3. #3
    SitePoint Enthusiast hombre_de_las_ca's Avatar
    Join Date
    Apr 2005
    Location
    Bangalore, India
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how about putting the %26 in the querry string in the first place!!!
    i.e when L&T is taken out from the database into the recordset and then appended to the url link how do i find if there is an "&" in the name and replace it with %26 so that on clicking on the link it is
    .../file.asp?Vname=L%26T

    also there wouldnt be just the &....', ", etc too will give the same prob...
    and so how and for how many characters would i have to do this??

    hombre_de_las Cavernas
    Don't ask what your Country can do for you,
    Ask what you can do for your Country.

  4. #4
    SitePoint Member
    Join Date
    Aug 2005
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hombre_de_las_ca, my English is not so good so I didn't understand the second problem you mention. Anyway, my first suggestion is that; avoid passing string trough url. If you can pass the Vendor_No instead of Vendor_Name then pass the number and then get the name using an SQL query.

    Also there is an URLEncode() function which I've not used. Maybe it can be useful for your problem. There is an example here:

    http://www.w3schools.com/asp/met_urlencode.asp

  5. #5
    SitePoint Enthusiast hombre_de_las_ca's Avatar
    Join Date
    Apr 2005
    Location
    Bangalore, India
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    o boy o boy....

    thanks a million....zuluuuuuu...
    it works

    hombre_de_las_cavernas
    Don't ask what your Country can do for you,
    Ask what you can do for your Country.

  6. #6
    SitePoint Enthusiast hombre_de_las_ca's Avatar
    Join Date
    Apr 2005
    Location
    Bangalore, India
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and it's just not that i can encode the url using URLEncode() function .....what i found out was that using the request.querystring(passed variable) on the linked page would actually decode the encoded url which is the answer to my second question that you did not understand......

    thanks again

    boy i love asp...

    hombre_de_las_cavernas
    Don't ask what your Country can do for you,
    Ask what you can do for your Country.

  7. #7
    SitePoint Member
    Join Date
    Aug 2005
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not at all


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •