简单的考勤系统,带单选按钮

时间:2016-01-18 11:21:30

标签: php time-and-attendance

我正在制作一个简单的考勤系统

我有这个带有单选按钮的PHP代码..现在我把它放在一个表中

我只能在整个桌子上选择一个单选按钮,而不是每个注册帐户选择一个单选按钮

<?php
session_start();
if(!isset($_SESSION["in"]))
{
    header("Location: log.php");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Attendance</title>

</head>
    <body>
<center>
<br />
<?php
echo "Today is " . date("m/d/Y") . "<br><br><br><br>";
?>

<?php
$conn= new mysqli("localhost", "root", "", "dbform");

    $sql = "SELECT * FROM tblusers";



$result = $conn->query($sql);
if ($result->num_rows > 0) {
    echo "<table width='1300' border='6'> 

<tr>
<th width='100'>ID</th>
<th width='100'>Lastname</th>
<th width='100'>Firstname</th>
<th width='100'>Sex</th>
<th width='100'>Attendance</th>
</tr>";
     // output data of each row
     while($row = $result->fetch_assoc()) {
         echo "<tr> ";
echo "<td align='center'>2016" . $row['id'] . "</td>";
echo "<td align='center'>" . $row['lastname'] . "</td>";
echo "<td align='center'>" . $row['firstname'] . "</td>";
echo "<td align='center'>" . $row['sex'] . "</td>";
?>
<form method="post" action="Succes_Submit_Attendace.php" name="submit_attendance">

attendance = 
<td align='center'> <label><input type="radio" name="attendance" value="present">Present</label>
              &emsp;<label><input type="radio" name="attendance" value="absent">Absent</label><br /><br />

<?php  

$row['attendance'] ;

?> </td>
<?php 
echo " </tr>";

     }
     echo "</table>";
} 
else {
     echo "0 results";
}
$conn->close();
?>   
<br>
<br>
<input type="reset">&emsp;<input type="submit" value="Submit Attendance"></h4>
</form>


<div align="right">
 <a href="admin.php"><h3>Back</h2></a>
</div>

1 个答案:

答案 0 :(得分:1)

所有单选按钮都具有相同的名称,因此您需要按行ID对它们进行分组。将输入类型更改为以下:

<label><input type="radio" name="attendance[<?php echo $row['id']; ?>]"  value="present">Present</label> 
&emsp;
<label><input type="radio" name="attendance[<?php echo $row['id']; ?>]" value="absent">Absent</label><br /> <br />

您的代码中也存在HTML错误。请修理它们