-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_student.php
99 lines (80 loc) · 2.5 KB
/
check_student.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
<?php
// Create a connection
$conn=mysqli_connect("localhost","root","","dbw");
if(!$conn){
die("Connection not Successfull!");
}
//print "Connection Created Succesfully! <br>";
// Retrieve user input
$user_id = $_POST['user_id'];
$password = $_POST['password'];
session_start();
$_SESSION['$tanya'] = $user_id;
// SQL query to check if the credentials are valid
$sql = "SELECT * FROM student WHERE user_id = '$user_id' AND pass = '$password'";
$result = mysqli_query($conn,$sql);
if (mysqli_num_rows($result) > 0) {
// "Sign-in Successful!";
// header("Location: courses_stud.php");
echo '<script>alert("Sign-in Successfull.");</script>';
// SQL query to extract course_name based on s_name
$rec = "SELECT c_id,c_name FROM courses WHERE s_name = '$user_id'";
$records = mysqli_query($conn,$rec);
if (mysqli_num_rows($records) > 0) {
// Fetch and display course_name(s)
while ($row=mysqli_fetch_array($records)) {
echo "Course ID: ".$row["c_id"]." Course Name: " . $row["c_name"] . "<br>";
}
} else {
echo "<br><br>You have not enrolled in any courses.<br><br>";
}
}
else {
// Invalid credentials. Redirect to student_login.html
echo '<script>alert("Invalid credentials.");</script>';
echo '<script>
setTimeout(function() {
window.location.href = "student_signin.html";
}, 1000); // Delay in milliseconds (e.g., 1000 = 1 second)
</script>';
exit(); // Ensure that no further code is executed after the redirect
}
// Close the connection
mysqli_close($conn);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Your Page Title</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 20px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
background-color: #4CAF50;
color: #fff;
border: none;
border-radius: 5px;
margin: 5px;
}
button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<form action="courses.html" method="get">
<button type="submit">Enroll in a New Course?</button>
</form>
<form action="home.html" method="get">
<button type="submit">LOGOUT</button>
</form>
</body>
</html>