-
Notifications
You must be signed in to change notification settings - Fork 0
/
student_change_password.php
79 lines (71 loc) · 3.48 KB
/
student_change_password.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
<!DOCTYPE html>
<?php
include "./includes/student_nav.inc.php";
include "./includes/config.inc.php";
if (isset($_COOKIE['lms_student'])) {
$studentId = $_COOKIE['lms_student'];
} else {
$message = "You need to login first";
echo "<script>alert(\"$message\")</script>";
echo "<script>window.location.href = '../index.php';</script>";
}
if (isset($_POST["submit"])) {
$new = $_POST["new"];
$current = $_POST["current"];
$confirm_new = $_POST["confirm_new"];
if (!($new == $confirm_new)) {
$message = "New password and Confirm Password are not same.";
echo "<script>alert(\"$message\")</script>";
echo "<script>window.location.href = './student_change_password.php';</script>";
exit;
}
$sql = "select * from `students` where studentId='$studentId' and password='$current'";
$result = mysqli_query($conn, $sql);
if ($result && mysqli_num_rows($result) > 0) {
$sql_update = "update `students` set password='$new' where studentId='$studentId'";
$result_update = mysqli_query($conn, $sql_update);
if ($result_update) {
$message = "Password has been change successfuly.";
echo "<script>alert(\"$message\")</script>";
echo "<script>window.location.href = './student_dashboard.php';</script>";
exit;
} else {
$message = "Something went wrong please try again.";
echo "<script>alert(\"$message\")</script>";
echo "<script>window.location.href = './student_change_password.php';</script>";
exit;
}
}
}
?>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.rtl.min.css" integrity="sha384-T5m5WERuXcjgzF8DAb7tRkByEZQGcpraRTinjpywg37AO96WoYN9+hrhDVoM6CaT" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<title>Change Student Password</title>
</head>
<body>
<div class="container h-100 w-100 m-5">
<h4 class="p-5 text-uppercase">Change Student Password</h4>
<form class="px-5" method="post">
<div class="mb-3">
<label for="exampleInputEmail1" class="form-label fw-bold">Current Password</label>
<input require type="password" name="current" class="form-control w-50" id="exampleInputEmail1" aria-describedby="emailHelp">
</div>
<div class="mb-3">
<label for="exampleInputEmail2" class="form-label fw-bold">Enter New Password</label>
<input require type="password" name="new" class="form-control w-50" id="exampleInputEmail2" aria-describedby="emailHelp">
</div>
<div class="mb-3">
<label for="exampleInputEmail3" class="form-label fw-bold">Confirm Password</label>
<input require type="password" name="confirm_new" class="form-control w-50" id="exampleInputEmail3" aria-describedby="emailHelp">
</div>
<button name="submit" type="submit" class="btn btn-primary">Change</button>
</form>
</div>
</body>
</html>