2014-04-23 78 views
0

我的複選框的問題是,它沒有發送值,因爲我想..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 = '&#10004;'; 
} else { 
$ok = ''; 
} 
?> 
<td class="center"> 
<?php echo $ok; ?> 
</td> 
<?php } ?> 
+0

什麼是<?php echo $ eq ['pos_unit_name']; ?>? ,它是動態的嗎?在隱藏的領域,可能你需要更新基於無線電選擇的值 – lampdev

+0

是的,它是動態的.. – haruya

+0

在你的html代碼..輸入複選框標籤動態生成,但它們具有相同的值屬性「檢查」 – namxee

回答

1

你真的應該填充您的複選框與您要發送的值。所以,你的複選框都應該得到的值A,B,C等。所以你的複選框都應該是這樣的:

<input name="check[]" class="checkbox" type="checkbox" value="<?php echo $eq['pos_unit_name']; ?>" style="opacity: 0;"> 

這樣一來,你的支票陣列將只能由你選擇這些值填充。

如果我沒有記錯,未勾選的複選框將不會被髮送。所以如果你只是選中複選框B,你的數組將只包含一個值。這樣,你就失去了與pos-Array的連接。

+0

它是,如果我檢查第二個數組,值是插入第一個數組,我如何使唯一的我檢查是唯一的價值是發送.. – haruya

+0

我編輯我的答案包括代碼,以便您的複選框將轉移價值,而不是隱藏的投入。 – Evan

+0

謝謝。它的作品像魅力..現在我只需要改變如何顯示它.. – haruya