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

    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)