我的複選框的問題是,它沒有發送值,因爲我想..php:我的foreach循環複選框沒有正確發送值
這是我的html代碼複選框。我使用foreach循環。
<form id="signupform" autocomplete="off" method="post" action="inputchecklist.php" class="form_container left_label">
<?php
$ew = mysql_query("select * from pos_unit where pos_unit_name like '%Director%'");
$row = mysql_num_rows($ew);
while($eq = mysql_fetch_array($ew))
{
$pos = $eq['pos_unit_name'];
$checklist = mysql_query("select * from checklist where check_pos = '$pos' and check_ok = 'Check'");
$excheck = mysql_fetch_array($checklist);
$poss = $excheck['check_pos'];
?>
<li>
<div class="form_grid_12">
<label class="field_title" ><?php echo $eq['pos_unit_name']; ?></label>
<div class="form_input">
<input name="check[]" class="checkbox" type="checkbox" value="<?php echo $eq['pos_unit_name']; ?>" style="opacity: 0;">
</div>
</div>
</li>
<?php } ?>
</form>
並且這對於插入件的PHP代碼..
<?php
include 'config.php';
$code = $_POST['code'];
$targ = $_POST['selectdistarg'];
$check = $_POST['check'];
$pos = $_POST['pos'];
foreach($pos as $index => $names)
{
$insert = mysql_query("insert into checklist (check_ok,check_pos,check_code) values ('$check[$index]','$names','$code')") or die (mysql_error());
}
$update = mysql_query("update corporate_kpi set kpi_dist_targ = '$targ' where kpi_code = '$code'");
?>
例如,
複選框1 - A, 複選框2 - B, 複選框3 - Visual C
如果我們選擇數字2,數值是B,但是我的代碼是,如果我們選擇數字2,數值是A,並且如果我們選擇數字3,那麼數值也是A,我不知道爲什麼..
這是基於DB
<?php
while ($eq = mysql_fetch_array($ew))
{
$pos = $eq['emp_data_pos'];
?>
<th><?php echo $eq['emp_data_pos']; ?></th>
<?php } ?>
的<th>
,這是<td>
值..
<?php $qq = mysql_query("select emp_data_pos from emp_data where emp_data_pos like '%Director%'");
while ($ee = mysql_fetch_array($qq))
{
$pos = $ee['emp_data_pos'];
$pos1 = mysql_real_escape_string($pos);
$aa = mysql_query("select * from checklist where check_pos = '$pos1' and check_code = '$code' and check_ok = 'Check'");
$bb = mysql_fetch_array($aa);
$ok = $bb['check_ok'];
if($ok != "")
{
$ok = '✔';
} else {
$ok = '';
}
?>
<td class="center">
<?php echo $ok; ?>
</td>
<?php } ?>
什麼是<?php echo $ eq ['pos_unit_name']; ?>? ,它是動態的嗎?在隱藏的領域,可能你需要更新基於無線電選擇的值 – lampdev
是的,它是動態的.. – haruya
在你的html代碼..輸入複選框標籤動態生成,但它們具有相同的值屬性「檢查」 – namxee