-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdate.php
135 lines (86 loc) · 3.69 KB
/
Update.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
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
require 'connection.php';
if($_POST['Change'] == 'Change'){
//Check valid username.
if (is_string($_POST['Old_Username'])) {
$old_username = $_POST['Old_Username'];
$sql = "select username,email,password from user where username ='$old_username' ";
$result = mysqli_query($conn, $sql);
$data = mysqli_fetch_assoc($result);
if($data){
if (trim($_POST['New_Username']) and trim($_POST['Old_Username'])) {
$new_username = $_POST['New_Username'];
if ($old_username == $new_username){
echo 'New username is same as the old one!';
echo '<br>';
}else{
$sql_2 = "select username from user where username ='$new_username'";
$result_2 = mysqli_query($conn, $sql_2);
$repeat_user = mysqli_fetch_assoc($result_2);
if(!$repeat_user){
$sql = "update user set username='$new_username' where username = '$old_username'";
$result = mysqli_query($conn, $sql);
if ($result) {
echo 'Change username successfully!';
echo '<br>';
}else{
echo 'Change username unsuccessfully!';
echo '<br>';
}
}else{
echo "New username is already exist!";
}
}
}
if (trim($_POST['New_Email'])) {
$new_email = $_POST['New_Email'];
if ($data['email'] == $new_email){
echo 'New email is same as the old one!';
echo '<br>';
}else{
$sql = "update user set email='$new_email' where username = '$old_username'";
$result = mysqli_query($conn, $sql);
if ($result) {
echo 'Change email successfully!';
echo '<br>';
}else{
echo 'Change email unsuccessfully!';
echo '<br>';
}
}
}
if(trim($_POST['New_Password'])){
if (trim($_POST['Old_Password'])) {
$new_password = $_POST['New_Password'];
$old_password = $_POST['Old_Password'];
if($data['password'] == $old_password){
if ($data['password'] == $new_password){
echo 'New password is same as the old one!';
echo '<br>';
}else{
$sql = "update user set password='$new_password' where username = '$old_username'";
$result = mysqli_query($conn, $sql);
if ($result) {
echo 'Change password successfully!';
echo '<br>';
}else{
echo 'Change password unsuccessfully!';
echo '<br>';
}
}
}else{
echo "Please input correct old password!";
}
}else{
echo "Please input old password first!";
}
}
}else{
echo "Username does not exist!";
}
}else{
echo "Please input valid username!";
}
}
mysqli_close($conn);
?>