我想使用复选框更新我的数据库。但似乎代码不会在foreach中循环。我哪里做错了 ?我的foreach
是否有任何问题?
<?php
foreach($_POST['listMenu'] as $checkBox1){
$strUpdateData = "
update tblMenuAkses
set MenuAkses = 'N'
where MenuAksesID = $checkBox1
";
$rsUpdateData = odbc_exec($dbconnVOT,$strUpdateData);
if($rsUpdateData){
echo "Success";
} else {
echo "ERROR <br>";
echo odbc_errormsg($dbconnVOT);
}
}
//It loops here
var_dump($_POST['listMenu']);
?>
<form method="post" action="skrinMenu.php" enctype="multipart/form-data">
<table align= "center" border="1" cellspacing="0" cellpadding="2">
<?php
$strgettable="select * from tblMenuAkses";
$varRecCount=0;
$rs=odbc_exec($dbconnVOT, $strgettable);
if($rs){
while (odbc_fetch_row($rs)) {// loop a table from database and checkbox too
$varRecCount++;
echo '<tr><td>';
echo '<center> '.$varRecCount.'</center>';
echo '</td>';
echo '<td>';
echo '<center> '.odbc_result($rs,"UsrGrpNama").'</center>';
echo '</td>';
echo '<td>';
echo '<center> '.odbc_result($rs,"MenuNama").'</center>';
echo '</td>';
echo '<td>';
echo '<center> '.odbc_result($rs,"MenuAkses").'</center>';
echo '</td>';
echo '<td>';
echo '<center> <input type="checkbox" name="listMenu[]" id="listMenu" value='.odbc_result($rs,"MenuAksesID").'> </center>';
echo '</td>';
echo '</td></tr>';
}
}
?>
</table>
<input type="submit" name="btnMenu" id="btnMenu" value = "Kemaskini">
</form>
var_dump($_POST['listMenu'])
的结果:NULL