簡體   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