views:

22

answers:

3

I have this:

    browse_cat.php?cat_gr='Mopeds & Traktors'">

The browse_cat.php contains this to fetch the above "category":

    $cat=$_GET['cat_gr'];
    echo $cat;

This echo outputs the first word only "Mopeds". It wont change if I replace the & with &.

What is the problem here?

The adress bar when I enter browse_cat.php shows:

  browse_cat.php?cat_gr='Mopeds%20&%20Traktors'

Thanks

A: 

%20 is the html entity for a space. URL shouldn't contain any.

MatTheCat
+2  A: 

Take a look at urlencode() and urldecode().
Also, remove the single quotes around your query string.

chigley
+1  A: 

Your url query values should not have quotes around them. You also need to urlencode the & and the spaces. Here is the correct url:

 browse_cat.php?cat_gr=Mopeds%20%26%20Traktors
Joel
How should I urlencode in html? I dont understand
Camran
You could use the php urlencode function to output the correct url, or use the javascript escape function generate the correct url. If the link is always the same, just use an online url encoder.
Joel
In JavaScript it would be `encodeURIComponent`, not the bogus `escape`.
bobince
By the way, if the url is being passed into PHP, you do not need to use urldecode(). PHP will automatically decode the value for you.
Joel