-4

大家好,我只是想问一下我的代码有什么问题,因为我要做的是确定是否选中了复选框。如果选中,则将其分配给“Y”,如果不是“N”。这是我的代码

HTML

<input type="checkbox" name="cash_delivery" />

PHP

$cash_delivery = $this->input->post('cash_delivery');

if(isset($cash_delivery)){
   echo 'Y';
}else{
   echo 'N';
}

exit;

我的问题是,如果我取消选中复选框,如果还选中了“Y”,它就会返回“Y”

这就是所有家伙提前感谢。顺便说一句,我正在使用 Codeigniter

4

3 回答 3

1
if(isset($cash_delivery)){
   echo 'Y';
}else{
   echo 'N';
}

由于先前的语句,将始终返回 true:

$cash_delivery = $this->input->post('cash_delivery');

你应该检查

if ($cash_delivery==false)
{
  //do domething
}
else 
{
  //do some other thing
}
于 2013-08-22T01:34:45.360 回答
0

$cash_delivery始终设置为已在此处初始化,$cash_delivery = $this->input->post('cash_delivery');. 尝试检查值$cash_delivery而不是isset()

于 2013-08-22T01:27:25.780 回答
0

好的,谢谢大家的回答,但我找到了解决方案。

而不是用于检查 $cash_delivery = $this->input->post('cash_delivery');

我使用了$_POST['cash_delivery']

这就是我所做的:

if(isset($_POST['cash_delivery'])){
   $val_delivery = 'Y';
}else{
   $val_delivery = 'N';
}
于 2013-08-22T01:33:05.473 回答