繁体   English   中英

如何更新php mysql中选定的复选框值?

[英]How to update selected checkbox values in php mysql?

提交时在 html 表选中复选框中,将选中的复选框值更新到 mysql 数据库

示例: update enquires set status = '2' where id in ( selected checkbox values)

复选框截图数据库

使用复选框的名称 attr 作为数组,如 'id[]'

喜欢。

<form method="post">
<table>
<tr>
        <td><input type="checkbox" value="<?php echo $row_id;?>" name="id[]"></td>
        <!-- other table data <td> -->
    </tr>

    <tr>
        <td><input type="checkbox" value="<?php echo $row_id;?>" name="id[]"></td>
        <!-- other table data <td> -->
    </tr>


</table>

<input type="submit" name="update_data" value="update">
</form>

提交表单后,您将获得数组中所有已检查的 id。 使用 implode 获取以逗号分隔的 id 并在更新查询中使用。

喜欢。

<?php

if(isset($_POST['update_data'])){
    echo $query_id = implode(',', $_POST['id']);

    //write the update query
}
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM