doulu3399 2018-12-04 20:01
浏览 94
已采纳

php - 使用复选框在循环内更新mysql

I'm trying to update all selected fields in the database using check box. This is the code that I've done, but it only updates the last record I choose from the checkbox list.

<tbody>
<?php while($row = mysqli_fetch_array($queryEmail)):?>
<tr>    
<td><input type="checkbox" name="formDoor[]" value=<?php echo $row['id'];?>> 
</td>
<td><?php echo $row['name'];?></td>
<td><?php echo $row['hour'];?></td>             
</tr>
<?php endwhile;?>
</tbody>
<?php
$hor = $_POST['hours']; //input value i want to update in selected id's
foreach ($_POST['formDoor'] as $entry){  
$sql = "UPDATE hora SET hour='$hor' WHERE id = $entry";  
}
?>
  • 写回答

1条回答 默认 最新

  • douyun8885 2018-12-04 20:18
    关注

    Try this You are forget to execute mysqli_query() on loop

    <tbody>
    <?php while($row = mysqli_fetch_array($queryEmail)):?>
        <tr>    
            <td>
                <input type="checkbox" name="formDoor[]" value=<?php echo $row['id'];?>> 
            </td>
            <td><?php echo $row['name'];?></td>
            <td><?php echo $row['hour'];?></td>             
        </tr>
    <?php endwhile;?>
    </tbody>
    
    <?php
    $hor = $_POST['hours']; //input value i want to update in selected id's
    foreach ($_POST['formDoor'] as $entry){  
       $sql = mysqli_query($con,"UPDATE hora SET hour='$hor' WHERE id = $entry");     
    }    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥65 LineageOs-21.0系统编译问题
  • ¥30 关于#c++#的问题,请各位专家解答!
  • ¥15 App的会员连续扣费
  • ¥15 不同数据类型的特征融合应该怎么做
  • ¥15 用proteus软件设计一个基于8086微处理器的简易温度计
  • ¥15 用联想小新14Pro
  • ¥15 multisim中关于74ls192n和DSWPK开关仿真图分析(减法计数器)
  • ¥15 w3wp,exe 中发生未处理的 Microsoft ,NETFramework 异常。
  • ¥20 C51单片机程序及仿真(加减器)
  • ¥15 AQWA | 水动力分析 二阶波浪力