-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin_forgot_password_code.php
More file actions
70 lines (63 loc) · 1.76 KB
/
admin_forgot_password_code.php
File metadata and controls
70 lines (63 loc) · 1.76 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
<?php
//taking all inputs
$adid = $_POST['ad_id'];
$email = $_POST['email'];
$new_pass = $_POST['pass_word'];
$con_new_pass = $_POST['con_pass_word'];
//check value is empty or not
if(!empty($adid) && !empty($email) && !empty($new_pass) && $new_pass!=null && !empty($con_new_pass))
{
//creating connection
$host = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbName = "museumsys";
// create connection
$conn = new mysqli($host, $dbUsername, $dbPassword, $dbName);
if(mysqli_connect_error()){
die('Connect Error(' . mysqli_connect_errno().')'.mysqli_connect_error());
}
else
{
//take out old password
$SELECT = "SELECT * FROM admin Where ad_id = ? LIMIT 1";
$UPDATE_PASS = "UPDATE admin SET pass_word = ? Where ad_id = ? LIMIT 1";
$stmt = $conn->prepare($SELECT);
$stmt->bind_param("s", $adid);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
$old_pass = $row["pass_word"];
if($adid == $row["ad_id"] && $email == $row["email"] && $new_pass==$con_new_pass){
//updating
$stmt->close();
$stmt = $conn->prepare($UPDATE_PASS);
$stmt->bind_param("ss", $new_pass, $adid);
$stmt->execute();
//check if updated successfully
$stmt->close();
$stmt = $conn->prepare($SELECT);
$stmt->bind_param("s", $adid);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
if($row["pass_word"] == $old_pass){
echo "<script>window.alert('Password unchanged')</script>";
}
else{
echo "<script>window.alert('Password changed successfully')</script>";
}
}
else{
echo "<script>window.alert('Id or email incorrect')</script>";
}
}
$stmt->close();
$conn->close();
}
else
{
echo "<script>window.alert('All fields are required')</script>";
die();
}
?>