注意:1表示已选中,0表示未选中
<input type='checkbox' name='payed' value='".$row['payed']."' /> //checkbox on form
检查从表单
收到的数据的代码段if (isset($_POST['payed']))
{
$sug_query = "Update invoices SET payed = 1, WHERE id = $id";
$db->exec($sug_query);
}
答案 0 :(得分:1)
只需检查复选框的名称是否作为POST变量存在:
if (isset($_POST['checkbox_name'])) {
//Checkbox was checked and you should update the column in question.
} else{
//Checkbox unticked. Set column to 0.
}
或者,使用三元运算符:
$val = isset($_POST['checkbox_name']) ? 1 : 0;
$sug_query = "Update invoices SET payed = $val WHERE id = $id";
$db->exec($sug_query);