forked from abid112/E-Commerce-Website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChangePass.php
122 lines (110 loc) · 2.76 KB
/
ChangePass.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
echo "hello";
include("data/db_connector.php");
session_start();
//echo $_SESSION['username'];
if(isset($_SESSION['username'])){
$id= $_SESSION['username'];
$sql = "SELECT * FROM user where UserID ='$id'";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC) or die(mysqli_error($conn));
$Opass = $row["Pass"];
//echo $Opass;
echo '
<html>
<head>
<style>
table, th, td {
border: 0px solid black;
border-collapse: collapse;
}
th, td {
padding: 20px;
}
</style>
</head>
<body><br>
<h1 align="center">DorDam</h1>
<h3 align="center">User Profile</h3>
<hr>
<br><br>
<form action="" method="post">
<table align="center">
<tr>
<td><strong>Your User Name :</strong></td>
<td><label>'.$id.'</label></td>
</tr>
<tr>
<td><strong>Enter Your Old Password </strong></td>
<td><input type="password" name="oldPass"/></td>
</tr>
<tr>
<td><strong>Enter Your New Password </strong></td>
<td><input type="password" name="newPass"/></td>
</tr>
<tr>
<td>
</td>
<td><input type="submit" name="go" value="Change Password"/></td>
</tr>
</table>
</form>
<table align="center">
<tr>
<td><form action="home.php" method="post">
<input type="submit" name="home" value ="Go Home Page" />
</form></td>
</tr>
</table>
</body>
</html>';
}
else{
echo '<HTML>
<head>
</head>
<body>
<br>
<h1 align="center">DorDam</h1>
<hr><br><br>
<h3 align="center">Log In first</h3>
<table align="center">
<tr>
<td><form action="LogIn.php" method="post">
<input type="submit" name="logIN" value ="Log In " />
</form></td>
<td><form action="home.php" method="post">
<input type="submit" name="home" value ="Go Home Page" />
</form></td>
</tr>
</table>
</body>
</HTML>';
}
?>
<?php
if(isset($_POST['go'])){
//echo 'pressed';
$oldPass=$_POST['oldPass'];
$newPass=$_POST['newPass'];
if($Opass==$oldPass){
//echo "you r allowed to change ur password";
$sql = "UPDATE user SET Pass='$newPass' WHERE UserID ='$id'";
if (mysqli_query($conn, $sql)) {
//echo "Record updated successfully";
$sql = "UPDATE log_in SET PassWord='$newPass' WHERE User_ID='$id'";
if (mysqli_query($conn, $sql)) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . mysqli_error($conn);
}
} else {
echo "Error updating record: " . mysqli_error($conn);
}
}
else{
echo "Password is not matched";
//echo $error;
}
}
?>