在一个表单中更新多行

时间:2015-02-15 12:12:45

标签: php

我想通过检查要更新的行来更新多行。 这是我的更新代码

release1.php:

$edittable=$_POST['selector'];
$N = count($edittable);
for($i=0; $i < $N; $i++)
{
$result = mysql_query("UPDATE `artcrimes`.`order_details` 
    SET `status` = 'Release' WHERE `order_details`.`details_id`='$edittable[$i]' ")
or die(mysql_error());
}    

然后下面是我的PHP代码。 release.php:

 <form role="form" name="add" method="post" action="release1.php">
 /...select function/

 while($row = mysql_fetch_array($result))

{
echo '<td><input name="selector[f]" action="release1.php" /* this is a checkbox*/
type="checkbox" value="'.$row['details_id'].'"></td>';
}
?>
</table></center>
<button type="submit" value ="update"
onClick="return confirm('Are you sure you want to release order?')" 
class="btn btn-default"
style="color:white; background-color:green; font-weight: bold ">SAVE</button>
</form>

它没有更新,但它们没有返回错误消息。

1 个答案:

答案 0 :(得分:0)

由于不推荐使用mysql_ *,请考虑切换为mysqliPDO。 您将结果作为数组提取,而不是使用像&#39; status&#39;这样的键。 所以在你的代码中:

while ($row = mysqli_fetch_array($result)) {

您正在尝试访问$ row [&#39; status&#39;]并且您应该访问它$ row [$ index] 其中$ index是0,1 ... 或者你可以改为:

while ($row = mysqli_fetch_assoc($result)) {

所以你可以像$ row [&#39; status&#39;] ...

那样访问它