dongyi7901 2018-06-01 20:52
浏览 72

使用PHP汇总选定的复选框值

I've been figuring out ways on how to work this out but I can't seem to. I'm a beginner in PHP and I'm so lost right now. I want to sum the selected checkboxes's values and post the sum of the values in a PHP page.

Here's my HTML so far

<input class="wrapped-input" type="checkbox" value="290" id="widgetu15650_input" name="custom_U15293[]" tabindex="1"/>
<label for="widgetu15650_input"></label>

Here's my PHP so far

if (isset($_POST['u15175'])) {
    if($_POST){
        $val = 0;
        foreach($_POST['custom_U15293'] as $custom_U15293){
            $val += $custom_U15293;
        }
        echo $val;
    }
}
  • 写回答

1条回答 默认 最新

  • dtio35880438 2018-06-01 21:06
    关注

    Try this,

      if($_POST){
        if(isset($_POST['custom_U15293']){
          $val = 0;
          foreach($_POST['custom_U15293'] as $custom_U15293){
          $val += (int) $custom_U15293;
        }
        echo $val;
      } else {
        echo 'Value not received';
      }
    

    If you see Value not received there is some problem with your HTML code

    评论

报告相同问题?