problem with drop down value in php
i have a drop down list which is populated dynamically from database table i.e
<form method=post action='dropdown.php'>
<?php
$query="SELECT DISTINCT style FROM style";
$result = mysql_query ($query);
echo "<select name=style[] size=4 value='' multiple>Choose Style</option>";
while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option value=$nt[style]>$nt[style]&l开发者_JS百科t;/option>";
}
echo "</select>";// Closing of list box
mysql_close($conn);?>
<input type=submit> </form>
When i post the form to another page the value of dropdown after space is not shown i.e if i select (Micro Pave) from drop down list then it will only show Micro. my php code is
$style=$_POST['style'];
if( is_array($style)){
while (list ($key, $val) = each ($style)) {
echo $val."<br/>";
}
}
echo "<option value='$nt[style]'>$nt[style]</option>";
Missed your single quotes! :)
<?php
$query = "SELECT DISTINCT style FROM style";
$result = mysql_query($query);
echo 'Choose Style
<select name="style[]" size="4" multiple="multiple">';
while ($nt = mysql_fetch_array($result)) {
echo '<option value="'.$nt['style'].'">'.$nt['style'].'</option>';
}
echo '</select>';
mysql_close($conn);
?>
missing quotes in the option value:
$ntstyle = htmlspecialchars($nt['style'], ENT_QUOTES);
echo "<option value='{$ntstyle}'>".$ntstyle."</option>";
Well for a start any attributes should be contained in double quotes.
echo "<option value=$nt[style]>$nt[style]</option>";
Should be
echo '<option value="'.$nt[style].'">'.$nt[style].'</option>';
So many things wrong unfortunately... :(
Start with "{$nt['style']}"
instead of just "$nt[style]"
.
(or better yet: echo 'Constant', $arr['item'];
)
Fix this:
echo "<select name=style[] size=4 value='' multiple>**Choose Style</option>**;
It's a wrong place for a label and the tag is not open!
Also add "" to your params="" in HTML.
精彩评论