Daniela Matteo
Daniela Matteo

Reputation: 13

Drop Down List and PHP

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'];  ?>

Upvotes: 1

Views: 131

Answers (2)

Daniel Krom
Daniel Krom

Reputation: 10060

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.

Upvotes: 0

Duniyadnd
Duniyadnd

Reputation: 4043

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>';

Upvotes: 3

Related Questions