【发布时间】:2014-09-26 15:21:01
【问题描述】:
此表中的值是从数据库生成的,请参见附图。现在我需要从表中的复选框中获取值以及 regno(注册号)或名称。
<form role="form" method="post">
<label class="attendance"><strong>Date:</strong></label>
<strong>
<input name="date" id="date" /></strong>
</div>
<table align="left" width="100%">
<tr>
<th>Rollno</th>
<th>Regno</th>
<th>Name</th>
<th>Status</th>
</tr>
<?php
$query = "SELECT * FROM student where course='M.Sc.Software Systems' and year='4' ";
$result=mysql_query($query) or die("Query Failed : ".mysql_error());
while($rows=mysql_fetch_array($result))
{
?>
<tr>
<td><?php echo $rows['rno'];?></td> // values of rollno from database
<td><?php echo $rows['regno']; ?></td> // values of regno from database
<td><?php echo $rows['name'];?></td>
<td>
<input type="checkbox" name="hour1" value="1"/>
<input type="checkbox" name="hour2" value="1"/>
<input type="checkbox" name="hour3" value="1"/>
<input type="checkbox" name="hour4" value="1"/>
<input type="checkbox" name="hour5" value="1" />
</td>
</tr>
<?php } ?>
</table>
<button name='insert' type="submit" class="contact">Submit</button>
</form>
<?php
if (isset($_POST['insert'])){
$regno = $rows['regno1'];
$hour1 = $_POST['hour1'];
$hour2 = $_POST['hour2'];
$hour3 = $_POST['hour3'];
$hour4 = $_POST['hour4'];
$hour5 = $_POST['hour5'];
$query2 = "INSERT INTO attendance (regno,hour1,hour2,hour3,hour4,hour5) VALUES ('$regno','$hour1','$hour2','$hour3','$hour4','$hour5')";
$result2=mysql_query($query2) or die("Query Failed : ".mysql_error());
$message="Successfully Added";
echo $message;
mysql_close($connect_mysql);
}
?>
【问题讨论】:
-
每一行都使用输入类型
hidden -
你能发布更多的代码吗?这是一个不完整的片段(以'?>'开头)你可能想要做的是使用内联 if 语句添加“checked”关键字,如: > (未经测试的代码)
-
为具有类似小时[]的数组的复选框赋予相同的名称
-
我是初学者,对此我不太了解
-
我尝试了 hour[] 但无法获得 regno 或 name