-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdate-password.php
More file actions
60 lines (35 loc) · 1.23 KB
/
Copy pathUpdate-password.php
File metadata and controls
60 lines (35 loc) · 1.23 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
<?php
require 'connection.php';
if($_POST['Change'] == 'Change'){
//Check valid username.
if (is_string($_POST['Username'])) {
$Old_username = $_POST['Username'];
$sql = "select username,password, from user where username ='$Old_username' ";
$result = mysqli_query($conn, $sql);
$data = mysqli_fetch_assoc($result);
if($data){
if (trim($_POST['new_password'])) {
$new_password = $_POST['new_password'];
if ($data['password'] == $new_password){
echo 'new password is same as the old one!';
}else{
$sql = "update user set password='$new_password' where username = '$username'";
$result = mysqli_query($conn, $sql);
if ($result) {
echo 'Change successfully!';
}else{
echo 'Change unsuccessfully!';
}
}
}else{
echo 'please input new password!';
}
}else{
echo "Username does not exist!";
}
}else{
echo "Please input valid username!";
}
}
mysqli_close($conn);
?>