DIEA
2021-11-05 10:40:05
提交時在 html 表選中復選框中,將選中的復選框值更新到 mysql 數據庫例子 : update enquires set status = '2' where id in ( selected checkbox values)
1 回答

楊魅力
TA貢獻1811條經驗 獲得超6個贊
使用復選框的名稱 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
}
?>
添加回答
舉報
0/150
提交
取消