php - 如何回显复选框组?

标签 php html css xhtml

有人可以帮助我吗?我无法通过多项选择回应我的复选框组。 每次我回显复选框组时,唯一显示的是我选中的最后一个框。

这是我的代码

<?php
$submit = $_POST['submit'];
$incharge = $_POST['incharge'];

if ($submit)
{
   echo $incharge;
}

?>

<table width="500" height="69">
      <tr>
        <td width="73"><label>
          <input type="checkbox" name="incharge" value="1" id="responsible_0" />
          MNFA</label></td>
          <td width="72"><label>
          <input type="checkbox" name="incharge" value="2" id="responsible_1" />
          HJB</label></td>
          <td width="70"><label>
          <input type="checkbox" name="incharge" value="3" id="responsible_2" />
          JBG</label></td>
          <td width="75"><label>
          <input type="checkbox" name="incharge" value="4" id="responsible_3" />
          MSG</label></td>
          <td width="275"><label>
          <input type="checkbox" name="incharge" value="5" id="responsible_4" />
          MGR</label></td>
      </tr>
      <tr>
      <td height="33"><label>
          <input type="checkbox" name="incharge" value="6" id="responsible_5" />
          AAP</label></td>
          <td><label>
          <input type="checkbox" name="incharge" value="7" id="responsible_6" />
          EPM</label></td>
          <td><label>
          <input type="checkbox" name="incharge" value="8" id="responsible_7" />
          SGA</label></td>
          <td><label>
          <input type="checkbox" name="incharge" value="9" id="responsible_8" />
          JLL</label></td>
          <td><label>
          <input type="checkbox" name="incharge" value="10" id="responsible_9" />
          AFM</label></td> 
      </tr>
    </table>

提前谢谢你......

最佳答案

将名称属性更改为:

name="incharge[]"

这将产生一个数组 $incharge。

请注意,您不能只回显该值;您将需要“print_r”或循环遍历它。

关于php - 如何回显复选框组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6727701/

相关文章:

javascript - 访问后如何创建链接没有任何样式规则

php - MySQL 查询为空

php - 动态为mysql查询中的所有字段名分配别名

php - PHP PDO 语句可以接受表名或列名作为参数吗?

php - 点击提交按钮后无法从数组中的数据库回显一个值(id)

javascript - 停止不同屏幕尺寸的 jquery。

javascript - 如何更改文本区域中文本的颜色

css - IE7 div 位置绝对不正确

html - 如何在 IE11 打印预览时避免分页?

javascript - JQuery:排除一个子元素