1

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

Hearner
  • 2,711
  • 3
  • 17
  • 34
  • possible duplicate of [What's wrong with putting spaces in $\_GET variables](http://stackoverflow.com/questions/6364793/whats-wrong-with-putting-spaces-in-get-variables) – Saty May 26 '15 at 14:11
  • Not a duplicate, but the code seems vulnerable to that issue, so take a look at it anyway @Hearner :) – Josef Engelfrost May 26 '15 at 14:25

3 Answers3

4

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">
Josef Engelfrost
  • 2,955
  • 1
  • 29
  • 38
1

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']);
foxbeefly
  • 510
  • 3
  • 13
0

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']);
Loko
  • 6,539
  • 14
  • 50
  • 78