-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathafter_course_registration.php
More file actions
74 lines (62 loc) · 2.05 KB
/
after_course_registration.php
File metadata and controls
74 lines (62 loc) · 2.05 KB
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
<?php
include('conn.php');
session_start();
// Ensure these POST values are set and not empty
$username = isset($_POST['Username']) ? $_POST['Username'] : null;
$course_selected = isset($_POST['course']) ? $_POST['course'] : null;
$value = 1001;
// Check if mandatory POST data is missing
if (empty($username) || empty($course_selected)) {
die("Error: Username or course is missing!");
}
// Insert the student into the registeredstudents table
$sql = "INSERT INTO `registeredstudents` (`student_username`, `Course_id`, `Course_Name`)
VALUES ('$username', '$value', '$course_selected');";
$res = mysqli_query($conn, $sql);
if ($res) {
echo'<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tuition Fee Waiver</title>
<link rel="stylesheet" href="x.css">
</head>
<body>
<header>
<div class="header-container">
<h1>TEACHWAVE -</h1>
<h2>TUITION POINT</h2>
</div>
</header>
<main>
</main>
</body>
</html>
';
// Fetch the Course_id for the given Course_Name
$sql1 = "SELECT `Course_id` FROM `courses` WHERE `Course_Name` = '$course_selected'";
$res1 = mysqli_query($conn, $sql1);
if ($res1) {
$row = mysqli_fetch_assoc($res1);
// Check if the result is not empty
if ($row) {
$x = $row['Course_id'];
// Update the courses table with the fetched Course_id
$sql2 = "UPDATE `courses` SET `Course_id` = '$x' WHERE `Course_Name` = '$course_selected'";
$res2 = mysqli_query($conn, $sql2);
if ($res2) {
echo "<h2> Registered successfully. </h2>";
} else {
echo "Error in updating Course_id: " . mysqli_error($conn);
}
} else {
echo "No Course_id found for the given Course_Name.";
}
} else {
echo "Error in fetching Course_id: " . mysqli_error($conn);
}
} else {
echo "Error in inserting row: " . mysqli_error($conn);
}
?>