-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_attendance.php
87 lines (62 loc) · 2.22 KB
/
update_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
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Establish database connection (replace these values with your actual database credentials)
$hostName = "sql312.infinityfree.com";
$dbUser = "if0_36313219";
$dbPassword = "zZZhkwieZwJhE0";
$dbName = "if0_36313219_loginform";
// Create connection
$conn = new mysqli($hostName, $dbUser, $dbPassword, $dbName);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if (!isset($_POST["attendance_text"])) {
die("Attendance data not received.");
}
// Get attendance data from the client-side
$attendanceText = $_POST["attendance_text"];
// Split the attendance text into individual records
$records = explode("\n", $attendanceText);
// Prepare a statement to insert attendance records
$stmt = $conn->prepare("INSERT INTO daily_attendance (date, roll_number, attendance) VALUES (?, ?, ?)");
// Check if the statement was prepared successfully
if (!$stmt) {
die("Error preparing statement: " . $conn->error);
}
// Check the format of the $records array
// var_dump($records);
foreach ($records as $record) {
// Split the record into roll number and attendance
list($rollNumber, $attendance) = explode(",", $record);
// Trim whitespace from the values
$rollNumber = trim($rollNumber);
$attendance = trim($attendance);
// Check if roll number is empty, if so, skip this record
if (empty($rollNumber)) {
continue;
}
// Get the current date in the format YYYY-MM-DD
$date = date("Y-m-d");
// Echo the roll number to console (for debugging)
// echo "Roll Number: $rollNumber\n";
// Execute the prepared statement with the attendance data
$stmt->bind_param("sss", $date, $rollNumber, $attendance);
$stmt->execute();
// Check if the execution was successful
if ($stmt->affected_rows === -1) {
die("Error executing statement: " . $stmt->error);
}
// Check for errors during insert operation
if ($stmt->errno) {
die("Error executing statement: " . $stmt->error);
}
}
// Close the statement
$stmt->close();
// Close the database connection
$conn->close();
// Send a response back to the client
echo "Attendance updated successfully!";
?>