1

I have a drop down list with Select Option and information written inside are retrieved from the database with a query .

<select name="moto">
      <?php 
        include 'connessione.php';
        $qry = "SELECT NomeOggetto FROM Oggetto";
        $result = mysql_query($qry);
        while($row = mysql_fetch_array($result))
        {
            echo '<option value='.$row["NomeOggetto"].'>'.$row["NomeOggetto"].'</option>';
        }
        ?>
</select>

The problem is that if in the menu i have the name of a motorbike with one space between its name , for example ( Kawasaki Ninja) , when i send it to the PHP page with the POST Method it only displays Kawasaki . How can i show the entire name with the space included ? this is the php page :

<?php  echo $_POST['moto'];  ?>
  • [Don't use `mysql_*` in an application; use `mysqli_*`](http://stackoverflow.com/questions/8891443/when-should-i-use-mysqli-instead-of-mysql). – Brendan Oct 11 '14 at 15:10
  • Doesn't work if i use mysqli . Values won't even show in the drop down list. – Daniela Matteo Oct 11 '14 at 15:13
  • `mysqli_*` will work *better* than `mysql_*` does. There was probably just a bug in your code - you would have been better off asking about that bug, plus this one. – Brendan Oct 11 '14 at 15:14
  • @DanielaMatteo The type of database of extension set used should play no issue. The suggestion to use mysqli is valid. If your code breaks it should be a simple task to debug to get it working right. – Giacomo1968 Oct 11 '14 at 15:48

2 Answers2

3

You have to put quotes around your attribute values in your HTML

from

echo '<option value='.$row["NomeOggetto"].'>'.$row["NomeOggetto"].'</option>';

to

echo '<option value="'.$row["NomeOggetto"].'">'.$row["NomeOggetto"].'</option>';
Duniyadnd
  • 4,013
  • 1
  • 22
  • 29
0

Try to send it with urlencode and decode it.

You can also print it as echo " '$_POST['moto']' " will print word1 word2 as 1 string because it is wrapped in quotes:

Try to print_r($_POST); and see if you're posting the entire string.

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
Daniel Krom
  • 9,751
  • 3
  • 43
  • 44