$ _POST ['变量']没有

时间:2015-07-28 09:58:33

标签: php html mysql

我有一个由PHP生成的工作选择。

代码:

echo "<form method='post'><select name='selectid'>";
$result_select = mysql_query("SELECT * FROM DB.Table");
  while($row_select = mysql_fetch_array($result_select))
    {
        echo "<option "; 
        if ($row['Value'] == $row_select['Value'] ) echo 'selected';
        echo ">{$row_select['Value']}&nbsp;&nbsp;&nbsp;{$row_select['Value']}
        </option>";
    }
echo "</select></form>";

现在的问题是,我想从select中选择$ _POST所选的值。它也在起作用。但是我希望得到没有&amp; nbsp

的字符串

我试过了:

$text_description="&nbsp;Helloworld!&nbsp;";
$text_description = str_replace('&nbsp;', '', $text_description);
echo $text_description;

它正在发挥作用。但是当我更换

 $text_description="&nbsp;Helloworld!&nbsp;";

 $text_description=$_POST['selectid'];

它不再起作用了。

1 个答案:

答案 0 :(得分:2)

您只需为选项添加值属性:

echo "<form method='post'><select name='selectid'>";
$result_select = mysql_query("SELECT * FROM DB.Table");
  while($row_select = mysql_fetch_array($result_select))
    {
        echo "<option value='{$row_select['Value']}'"; 
        if ($row['Value'] == $row_select['Value'] ) echo 'selected';
        echo ">{$row_select['Value']}&nbsp;&nbsp;&nbsp;{$row_select['Value']}
        </option>";
    }
echo "</select></form>";