我希望这是一件小事。在梳理了几个小时并尝试了各种变化之后,我决定让专业人士对此有所了解。我有一个页面设置来轻松管理数据库。基本上只是为了更新一行或删除它。对于每一行,我都有一个复选框来更新行,复选框来删除,三列来自数据库的信息,然后两列带有下拉框来更改值。问题是无论我从下拉列表中选择什么值,它总是发布相同的值。使用 print_r($_POST) 我可以看到它实际上返回了错误的值。废话不多说,代码:
这是我页面的顶部(表单发布到自身):
if(isset($_POST['checkbox'])){
$product = $_POST['product_choice'];
$status = $_POST['status_choice'];
$checkbox = $_POST['checkbox'];
if(isset($_POST['update'])){
$update = $_POST["update"];
}
$id = "('" . implode( "','", $checkbox ) . "');" ;
$sql="UPDATE test_orders SET product='$product',status = '$status' WHERE ordNum IN $id" ;
$result = mysql_query($sql) or die(mysql_error());
}
和形式:
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="frmactive" method="post" action="">
<table width="400" border="0" cellpadding="3" cellspacing="1">
<!--BUTTONS-->
<tr>
<td colspan="6"><input name="update" type="submit" id="update" value="Upate" />
<input name="delete" type="submit" id="delete" value="Delete" /></td>
</tr>
<tr>
<td> </td>
<td colspan="5"><strong>Update multiple rows in mysql with checkbox</strong> </td>
</tr>
<tr>
<td style="background: #ddd; padding:5px; border-left:1px solid #ccc; border-top:1px solid #ccc;">Update?</td>
<td style="background: #ddd; padding:5px; border-left:1px solid #ccc; border-top:1px solid #ccc;">Delete?</td>
<td style="background: #ddd; padding:5px; border-left:1px solid #ccc; border-top:1px solid #ccc;">Order #</td>
<td style="background: #ddd; padding:5px; border-left:1px solid #ccc; border-top:1px solid #ccc;">Name</td>
<td style="background: #ddd; padding:5px; border-left:1px solid #ccc; border-top:1px solid #ccc;">Job Name</td>
<td style="background: #ddd; padding:5px; border-left:1px solid #ccc; border-top:1px solid #ccc;">Product</td>
<td style="background: #ddd; padding:5px; border-left:1px solid #ccc; border-top:1px solid #ccc;">Status</td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['ordNum']; ?>"></td>
<td bgcolor="#FF0000" align="center"><input type="checkbox" name="delete[]" id="delete[]" value="<? echo $rows['ordNum']; ?>" /></td>
<td><? echo $rows['ordNum']; ?></td>
<td><? echo $rows['name']; ?></td>
<td><? echo $rows['OrderDesc']; ?></td>
<td>
<select name="product_choice" id="product" style="font-size:10px;">
<option value="<? echo $rows['product']; ?>" selected="selected"><? echo $rows['product']; ?>
</option>
<option value="Color Correction"> Color Correction </option>
<option value="Basic retouch"> Basic retouch </option>
<option value="Extensive Retouch"> Extensive Retouch </option>
<option value="Signature Work"> Signature Work </option>
<option value="Signature Oil"> Signature Oil </option>
<option value="Web Design"> Web Design </option>
<option value="Print Design"> Print Design </option>
<option value="Other"> Other </option>
</select>
</td>
<td>
<select name="status_choice" id="status" style="font-size:10px;">
<option value="<? echo $rows['status']; ?>" selected="selected"><? echo $rows['status']; ?></option>
<option value="Order Received"> Order Received </option>
<option value="in the works"> in the works </option>
<option value="waiting to upload"> waiting to upload </option>
<option value="uploading"> uploading </option>
<option value="ON HOLD"> ON HOLD </option>
<option value="awaiting decision"> awaiting decision </option>
<option value="proof sent"> proof sent </option>
<option value="next invoice"> next invoice </option>
<option value="waiting images/order"> waiting images/order </option>
<option value="invoiced"> invoiced </option>
<option value="complete"> complete </option>
<option value="paid"> paid </option>
<option value="making changes"> making changes </option>
</select>
</td>
</tr>
<?php
}
?>
<tr>
<td colspan="6" align="center"> </td>
</tr>
</table>
</form>
</td>
</tr>
</table>
这是 print_r($_POST); 的结果 无论我在下拉菜单中选择什么选项。[product_choice] 和 [status_choice] 始终相同。
Array ( [update] => Upate [checkbox] => Array ( [0] => 113 ) [product_choice] => Extensive Retouch [status_choice] => Order Received )
谢谢你的帮助。
** * *已解决* ** * ** * ** 得到朋友的帮助,工作良好如下