-
Notifications
You must be signed in to change notification settings - Fork 0
/
take_attendance.php
119 lines (95 loc) · 3.12 KB
/
take_attendance.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
session_start();
// to disable back after logged out
if(!isset($_SESSION['logged_in']))
echo "<script>window.location.href='index.php';</script>";
include("db.php");
include("header.php");
if(isset($_POST['submit']))
{
$date=date("d-m-Y");
$subject=$_SESSION["subject"];
$period=$_SESSION["period"];
///check if already attendance marked for this period on this day.
$check=mysqli_query($con,"Select * from attendance where date='$date' and period='$period'; ");
if(mysqli_num_rows($check)>0)
{
echo "<script>
alert('Attendance marked for this period!');
window.location.href='home.php';
</script>";
}
else
{
foreach($_POST['attendance_status'] as $id=>$attendance_status)
{
$name=$_POST['student_name'][$id];
$admno=$_POST['admno'][$id];
$resul=mysqli_query($con,"insert into attendance(admno,name,subject,status,period,date) values('$admno','$name','$subject',
'$attendance_status','$period','$date'); ");
}
if($resul)
{
unset($_SESSION["period"]);
echo "<script>
alert('Data saved successfully.');
window.location.href='home.php';
</script>";
}
}
}
?>
<div class="container">
<h2><center><b>Attendance<b></center> </h2>
<div class="panel panel-default">
<div class="well text-center">
<?php $_SESSION["period"]=$_POST["period"]; ?>
<center><h3>Welcome <?php echo strtoupper($_SESSION['name']); ?> <br></h3><h4>
<?php echo strtoupper($_SESSION['subject']);?> Period <?php echo $_SESSION["period"]; ?></h4>
</center>
<h4>Date: <?php echo date("d-m-Y"); ?></h4>
</div>
<div class="panel panel-body">
<form action="" method="post">
<table class="table table-stripped">
<tr>
<th>Serial Number</th> <th>Student Name</th> <th>Roll Number</th> <th>Attendance Status</th>
</tr>
<!-- to display values in table using loop -->
<?php $result=mysqli_query($con,"select * from student");
// below variable for displaying serial number
$serialnumber=0;
// below variable for radio button
$counter=0;
while($row=mysqli_fetch_array($result))
{
$serialnumber++;
?>
<tr>
<td><?php echo $serialnumber; ?> </td>
<td><?php echo $row['name']; ?>
<input type="hidden" value="<?php echo $row['name']; ?>" name="student_name[]">
</td>
<td><?php echo $row['admno']; ?>
<input type="hidden" value="<?php echo $row['admno']; ?>" name="admno[]">
</td>
<td>
<!-- attendance_status[0], [1], [2] etc save as array which is used in php above to store in db-->
<input type="radio" name="attendance_status[<?php echo $counter; ?>]" value="Present" required>Present
<input type="radio" name="attendance_status[<?php echo $counter; ?>]" value="Absent" required>Absent
</td>
</tr>
<!-- loop ends -->
<?php
//increment counter variable for radio button
$counter++;
}
?>
</table>
<center>
<input type="submit" name="submit" value="Submit" class="btn btn-primary btn-lg">
</center>
</form>
</div>
</div>
</div>