gpt4 book ai didi

php - 如何使用php更新数据库中选中的值和未选中的值?

转载 作者:太空宇宙 更新时间:2023-11-03 11:54:46 24 4
gpt4 key购买 nike

<分区>

我有多个复选框。一旦用户检查我需要将这些值存储到数据库中。如何根据检查值将其存储在数据库中。我尝试使用以下代码,但它不起作用。请就此提出建议

 <input name="weekdays[]" val="mon">
<input name="weekdays[]" val="tue">
<input name="weekdays[]" val="wed">
<input name="weekdays[]" val="fri">
<input name="weekdays[]" val="sat">
$get_array = $_POST['weekdays'];
foreach($get_array as $value){
// if monday not having value set zero in column
// update into multiple column
//update table set is_monday_available=$mon,is_tue_availble=$tues,etc where id= busi_id
}

解决方案:

  foreach ($get_checkbox as $key => $check) {

if(in_array("mon",$get_checkbox)){
$values['mon'] = 1;
}else{
$values['mon'] = 0;
}
if(in_array("tue",$get_checkbox)){
$values['tue'] = 1;
}else{
$values['tue'] = 0;
}
if(in_array("wed",$get_checkbox)){
$values['wed'] = 1;
}else{
$values['wed'] = 0;
}
if(in_array("thu",$get_checkbox)){
$values['thu']= 1;
}else{
$values['thu']= 0;
}
if(in_array("fri",$get_checkbox)){
$values['fri'] = 1;
}else{
$values['fri'] = 0;
}
if(in_array("sat",$get_checkbox)){
$values['sat'] = 1;
}else{
$values['sat'] = 0;
}
if(in_array("sun",$get_checkbox)){
$values['sun'] = 1;
}else{
$values['sun'] = 0;
}

}

$update_data = array("is_monday_available" => $values['mon'],
"is_tuesday_available" => $values['tue'],
"is_wednesday_available" =>$values['wed'],
"is_thursday_available" => $values['thu'],
"is_friday_available" => $values['fri'],
"is_saturday_available" => $values['sat'],
"is_sunday_available" => $values['sun']
);

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