I have a problem when populating drop-down list from MySQL with fields that contain two or more words.
For instance, when I populate the drop-down with names it says John Smith, but when I enter data in another table from that drop-down, only John is stored in the database without Smith.
What could be the problem?
Here’s the code:
<td>
<select name="opstina">
<option value=></option>
<?php
$query = mysql_query("SELECT * FROM opstine");
while($podaci = mysql_fetch_array($query))
{
echo "<option value= {$podaci['naziv']}>{$podaci['naziv']}</option>";
}
?>
</select>
</td>
It’s likely that you need to quote your values …
Otherwise it ends up being
<option value=John Smith>in the HTML and only John would be assigned to the value … you want it to be<option value="John Smith">…