-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_student_grade.php
36 lines (30 loc) · 1.08 KB
/
add_student_grade.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
<?
require_once ("db_conn.php");
$conn = connect_db();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Check the connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Retrieve the ID to be edited
$school_id = $_POST['school_id'];
$prelim = $_POST['prelim'];
$midterm = $_POST['midterm'];
$finals = $_POST['finals'];
$statement = $conn->prepare("INSERT INTO `tbl_students_grades` (`school_id`, `grades_id`, `prelim`, `midterm`, `finals`) VALUES (?, NULL, ?, ?, ?)");
$statement->bind_param("sddd", $school_id, $prelim, $midterm, $finals);
if ($statement->execute()) {
http_response_code(200);
echo "<script>alert(Successfully added grade!)</script>";
} else {
// If update fails
http_response_code(500);
echo "<script>alert(Error updating data: {$conn->error})</script>";
}
// Close the connection
$statement->close();
$conn->close();
} else {
http_response_code(405);
echo "<script>alert(\"Wrong HTTP request used! Try again.\")</script>";
}