0
提前
感谢我在做什么是我创建了一个表中的MySQL与记录的细节像(ID,姓名,日期)和另一个表个人信息插入表值像(ID,姓名,地址,批号,出生日期,性别,血型等) 我想要做的是,我想的形式来从个人详细一些细节,如名批次表现在我想要另一个字段与复选框它应该在每一行 现在选择几个复选框和提交按钮它应该能够在不选择以从记录表从个人细节表和复选框的作为1上选择的值或0插入取出的数据。我已经尝试了代码,但无法找出解决方案。无法使用循环
这是我的完整代码的一部分
require_once('connect.php'); // contains my connection
$select_query="SELECT * FROM personal WHERE batch='161'";
$result=mysql_query($select_query);
if(!$result)
{
$error="there was some error try again later";
}
?>
<div class="module-table-body" >
<form method="post">
<table id="myTable" class="tablesorter" align="center">
<thead>
<tr>
<th style="">#</th>
<th style="">Full name</th>
<th style="">Batch</th>
<th style=""> Present/Absent</th>
</tr>
</thead>
<tbody>
<?php
while($row=mysql_fetch_array($result))
{
?>
<tr>
<td ><?php echo $row['id']; ?></td>
<td ><?php echo $row['full_name']; ?></td>
<td><?php echo $row['batch']; ?></td>
<td>
<input name="checkbox[]" type="checkbox" value="<?php echo $row['id']; ?>">
</td>
</tr>
<?php
}
?>
<tr>
<td>
<input name="save" type="submit" value="Save" /></td></tr>
</tbody>
</table>
<?php
if(isset($_POST['save']))
{
$box=$_POST['checkbox'];
foreach($box as $id)
{
$box= isset($_POST['checkbox']) && $_POST['checkbox'] ? "1" : "0" ;
$insert="INSERT INTO record VALUES('','$fname','$date','$box')";
$res=mysql_query($insert);
if(!$res)
{
echo mysql_error();
}
else
{
echo "updated successfully";
}
}
}
?>
代码工作,只有插入,只有零复选框值
如何请详细说明 –
循环中的$ box变量覆盖:foreach($ box as $ id)。每次循环执行$ box值都会因$ box = isset()而改变..... – Thomas