gpt4 book ai didi

php - 如何编辑带有复选框的表单并在数据库端反射(reflect)更改

转载 作者:行者123 更新时间:2023-11-29 13:18:14 24 4
gpt4 key购买 nike

注: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);
}

最佳答案

只需检查复选框的名称是否作为 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);

关于php - 如何编辑带有复选框的表单并在数据库端反射(reflect)更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21196688/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com