【发布时间】:2014-03-24 14:17:24
【问题描述】:
我有一个显示库存水平的表单,我希望用户能够删除多个产品,因此提供了复选框。代码如下:
echo "<form method='get'>
<input type='submit' name='removestock' value= 'Remove'>
<table class='display' border='0'>
<tr>
<th>Select</th>
<th>Name</th>
<th>Description</th>
<th>Price (£)</th>
<th>Quantity</th>
<th>Size</th>
</tr>";
echo "<tr>";
require ('connection.php');
$query = mysql_query("SELECT * FROM items")or die(mysql_error());
while($results = mysql_fetch_array($query)){
echo "<td> <input type='checkbox' name='item' value='".$results['item_id']."'></td>";
echo "<td>" . $results['name'] . "</td>";
echo "<td>" . $results['description'] . "</td>";
echo "<td>" . $results['price'] . "</td>";
echo "<td>" . $results['quantity'] . "</td>";
echo "<td>" . $results['size_id'] . "</td>";
echo "</tr>";
}
echo "</table></form>";
而我的解析代码是……
if(isset($_GET['removestock']) === true){
$errors = array();
$items = $_GET['item'];
echo $items;
}
但由于某种原因,它只显示最后选择的 item_id。您的帮助将不胜感激! PS。我尝试将复选框名称更改为 name="items[]" 并实现了一个 foreach 循环来解析数据,但它仍然不起作用。
【问题讨论】: