Hearner
Hearner

Reputation: 2709

$_GET value from URL that contains space

I have a table with a clickable row and a textbox which value is the name clicked on the row, easy. This is a sample of my code. The table :

<table border="2">
        <tbody>
            <tr>
                <td>Categorie number</td>
                <td>Categorie name</td>
            </tr>
                <?php
                    $SQLCategorie = mysqli_query($db,'SELECT * FROM categorie ORDER BY Name_categorie');
                    while($row= mysqli_fetch_array($SQLCategorie))
                    {
                        echo '<td>' .$row[0]. '</td>';
                            echo "<td><a href='GererCategorie.php?Name_categorie=".$row[1]."' >".$row[1]."</a></td>";  
                        echo "</tr>";
                    }
                ?>  
        </tbody>
</table>

And the textbox :

<input type="text" name="Delete_Categorie" 
                    <?php 
                        if (isset($_GET['Name_categorie'])) 
                        {
                            echo "value=".$_GET['Name_categorie'];
                        }
                    ?>
>

Everything works fine but I have a weird problem. For example I have INTERNET EXPLORER in my database and my URL looks like ?Name_categorie=INTERNET%20EXPLORER. The textbox only shows INTERNET, I CANNOT echo INTERNET EXPLORER.

I know that my probleme may seem easy but I have no idea how to echo the full name. I need to get it because I have EXCEL 2003 and EXCEL 2010 but it only shows EXCEL. For EXCEL 2010 I have in my URL EXCEL%202010

Upvotes: 1

Views: 3903

Answers (3)

Loko
Loko

Reputation: 6679

As alternative, you could replace a white space with a _ before using it in the href="" and then after you get the value of the textbox you can replace the _ with a whitespace again.

Example:

echo "<td><a href='GererCategorie.php?Name_categorie=".str_replace(' ', '_',$row[1])."' >".$row[1]."</a></td>";

and in your value:

echo "value=".str_replace('_', ' ',$_GET['Name_categorie']);

Upvotes: 0

Josef Engelfrost
Josef Engelfrost

Reputation: 2965

Take a look at the HTML you are generating, your output will look something like this:

<input type="text" name="Delete_Categorie" value=INTERNET EXPLORER>

So the browser will read this as value being INTERNET, and EXPLORER will be interpreted as an attribute name.

You need to add quotes around your text.

echo "value=\"".$_GET['Name_categorie']."\"";

This will output

<input type="text" name="Delete_Categorie" value="INTERNET EXPLORER">

Upvotes: 4

foxbeefly
foxbeefly

Reputation: 530

You need to urlencode()

echo "<td><a href='GererCategorie.php?Name_categorie=".urlencode($row[1])."' >".$row[1]."</a></td>";

and then urldecode()

echo "value=".urldecode($_GET['Name_categorie']);

Upvotes: 1

Related Questions