Php 使用复选框发送多个值
我有一张表格,该表格包含以下表格:Php 使用复选框发送多个值,php,checkbox,Php,Checkbox,我有一张表格,该表格包含以下表格: <?php foreach($resultTable as $key => $value) { ?> <table> <tr> <td><input type = "checkbox" name="idPriv[]" id="idPriv" onclick="evaluateIT(this)" data-related
<?php foreach($resultTable as $key => $value)
{
?>
<table>
<tr>
<td><input type = "checkbox" name="idPriv[]" id="idPriv" onclick="evaluateIT(this)" data-related-item="adminPanelShow" value ="<?php echo $value["id"]?>" />
<input name="rowID[]" id="rowID[]" class="adminPanel" hidden="hidden" type="text" value="<?php echo $value["id"]?>"/></td>
<td><input type="text" name="userName[]" id="userName" class="adminPanel" value="<?php echo $value["userName"]?>"/></td>
<td><input name="firstName[]" type="text" id="firstName" class="adminPanel" value="<?php echo $value["firstName"]?>"/></td>
</tr>
<?php } ?>
</table>
要检查复选框是否选中,请按如下方式对其进行分析:
foreach($resultTable as $key => $value)
{
if($value==="on")
{
// checked checkbox has a value of "on"
// triple = sign means value is exactly "on"
}
}
用复选框值连接每个用户名
,名字
字段:
foreach($resultTable as $key => $value)
{?>
<table>
<tr>
<td><input type = "checkbox" name="idPriv[]" id="idPriv" onclick="evaluateIT(this)" data-related-item="adminPanelShow" value ="<?php echo $value["id"]?>" />
<input name="rowID[]" id="rowID[]" class="adminPanel" hidden="hidden" type="text" value="<?php echo $value["id"]?>"/></td>
<td><input type="text" name="userName[<?php echo $value["id"]?>]" id="userName" class="adminPanel" value="<?php echo $value["userName"]?>"/></td>
^--- here
<td><input name="firstName[<?php echo $value["id"]?>]" type="text" id="firstName" class="adminPanel" value="<?php echo $value["firstName"]?>"/></td>
^--- here
</tr>
}
</table>
name=“userName[]”
您的标记失败。修好它。(您正在打开但没有关闭表,为什么您一直在打开新表?。
foreach ($_POST[`idPriv`] as $id) {
$firstName = $_POST['firstName'][$id];
$userName = $_POST['userName'][$id];
// ...
}