-
Notifications
You must be signed in to change notification settings - Fork 1
/
store_attendance.php
138 lines (96 loc) · 3.59 KB
/
store_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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
session_start();
$posted = array();
$att_array = array();
$name_array = array();
$roll_array = array();
$time = time();
$day = date('d');
$month = date('m');
$year = date('Y');
if(isset($_SESSION['username']) && isset($_SESSION['password']))
{
$name_array = $_SESSION['name_array'];
$roll_array = $_SESSION['roll_array'];
foreach ($_SESSION['radioKeys'] as $radioKey) {
# code...
if (isset($_POST[$radioKey])) {
$posted[$radioKey] = $_POST[$radioKey];
}
}
$_SESSION['radio'] = $posted;
foreach ($_SESSION['radio'] as $radioKey => $radioValue)
{
//var_dump($radioValue);
$att_array[] = $radioValue;
}
if (!empty($name_array) && !empty($roll_array) && !empty($att_array) && !empty($day) && !empty($month) && !empty($year) ) {
$host_name = 'localhost';
$user = 'root';
$password = '';
$database = 'attendance';
$connection = mysqli_connect($host_name,$user,$password,$database);
if ($connection) {
//echo "Connected to the DB <br>";
# code...
}
else
{
echo "Not Connected".mysqli_error($connection);
}
$name_values = array();
$roll_values = array();
$att_values = array();
if ($_SESSION['class'] == 'class10') {
/*$day_check = "SELECT * FROM `aclass10` WHERE `day` = '".$day."' && `month` = '".$month."' && `year` = '".$year."' ";
$check_day = mysqli_query($connection,$day_check);
if ($check_day) {
echo "Attendance already added"; //this is to restrict if the attendance is already added for the present day.
die();
}
else
{*/
foreach ($name_array as $key => $name_values) {
$name_values = mysqli_real_escape_string($connection,$name_values);
$roll_values = mysqli_real_escape_string($connection,$roll_array[$key]);
$att_values = mysqli_real_escape_string($connection,$att_array[$key]);
$sql= "INSERT INTO `aclass10` (Name , attendance , RollNo , day , month , year) VALUES ('$name_values' , '$att_values' , '$roll_values' ,'$day' , '$month' , '$year')";
$result = mysqli_query($connection,$sql);
}
#}
# code...
}
if ($_SESSION['class'] == 'class12') {
/*$day_check = "SELECT * FROM `aclass12` WHERE `day` = '".$day."' && `month` = '".$month."' && `year` = '".$year."' ";
$check_day = mysqli_query($connection,$day_check);
if ($check_day) {
echo "Attendance already added";
die();
}
else
{*/
foreach ($name_array as $key => $name_values) {
$name_values = mysqli_real_escape_string($connection,$name_values);
$roll_values = mysqli_real_escape_string($connection,$roll_array[$key]);
$att_values = mysqli_real_escape_string($connection,$att_array[$key]);
$sql= "INSERT INTO `aclass12` (Name , attendance , RollNo , day , month , year) VALUES ('$name_values' , '$att_values' , '$roll_values' ,'$day' , '$month' , '$year')";
$result = mysqli_query($connection,$sql);
}
#}
# code...
}
if($result)
{
echo "Attendance Succesfully added";
}
else
{
echo "Data Not added".mysqli_error($connection);
}
}
}
else
{
require 'redirect_login.php';
}
?>