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'];  ?>
3
  • Don't use mysql_* in an application; use mysqli_*. Commented Oct 11, 2014 at 15:10
  • Doesn't work if i use mysqli . Values won't even show in the drop down list. Commented Oct 11, 2014 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. Commented Oct 11, 2014 at 15:14

2 Answers 2

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>';
Sign up to request clarification or add additional context in comments.

Comments

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.

1 Comment

An HTML select will automatically urlencode the data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.