-6
的代碼從數據庫中填充組合框如何獲得選擇從組合框的形式值在PHP提交
<td>Item Name:</td>
<td><select name="items">
<option value="0" selected="selected"> Choose</option>
<?php
while($row = mysql_fetch_assoc($query))
{
$category = $row["ItemName"];
echo "$category";
?>
<option value= <?php $category ?> > <?php echo $category ?> </option>
<?php
}?>
</select></td>
代碼提交
<td><input type="submit" name="newItem" value="New Item"/></td>
PHP代碼爲:
<?php
if(isset($_POST['newItem']))
{
$item=$_POST['items'];
$sel=mysql_query("select ItemID from itemmaster where ItemName='$item'");
while($row2 = mysql_fetch_array($sel))
{
//code
}
值應該是引號裏的'<期權價值= 「<?PHP $類別>」>' –
**危險**:您正在使用[an **過時的**數據庫API](http://stackoverflow.com/q/12859942/19068)並應使用[現代替換] (http://php.net/manual/en/mysqlinfo.api.choosing.php)。你也**易受[SQL注入攻擊](http://bobby-tables.com/)**,現代的API會使[防禦]更容易(http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php)自己從。 – Quentin
您已經在問題中獲得代碼以從您的select元素中獲取值。問題是什麼? – Quentin