-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdateDelete.php
104 lines (78 loc) · 2.53 KB
/
UpdateDelete.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
<?php
if (!empty($_POST)) {
$username = "";
if (empty($_POST["username"])) {
$response["success"] = 0;
$response["message"] = "Did not receive any username.";
die(json_encode($response));
} else{
$username = trim($_POST["username"]);
}
}else{
$response["success"] = 0;
$response["message"] = "Did not receive any data.";
die(json_decode($response));
}
$con = mysqli_connect("localhost", "root", "WhatHappendPWD.", "whathappend");
if(mysqli_connect_error()){
echo "failed to connect".mysqli_connect_error();
}
if($_POST("updateUserData")){
if(empty($_POST["pwd"]) || empty($_POST["email"])){
$response["success"] = 0;
$response["message"] = "New password or the new email is empty.";
die(json_decode($response));
} else{
$newPwd = $_POST["pwd"];
$newEmail = $_POST["email"];
$query = "UPDATE users SET `pwd` = '".$newPwd."', `email`='".$newEmail."' WHERE username = '".$username."'";
if (!mysqli_query($con,$query)) {
$response["success"] = 0;
$response["message"] = "Problem with updating the user info. Please try again.";
die(json_encode($response));
}
else{
$response["success"] = 1;
$response["message"] = "Userinfo updated.";
die(json_encode($response));
}
}
}
else if($_POST("deleteUserData")){
$query = "DELETE FROM users WHERE username = '".$username."'";
if (!mysqli_query($con,$query)) {
$response["success"] = 0;
$response["message"] = "Problem with deleting user info. Please try again.";
die(json_encode($response));
}
else{
$response["success"] = 1;
$response["message"] = "Userinfo deleted.";
die(json_encode($response));
}
}
else{
//Find the users info
$query = "SELECT * FROM users WHERE `username` = '".$username."'";
if ($result = $con->query($query)) {
$response["success"] = 1;
$response["message"] = "User with that username available.";
$response["userInfo"] = array();
/* fetch associative array */
while ($row = $result->fetch_assoc()) {
if($distance < $row["range"]){
$post = array();
$post["id"] = $row["id"];
$post["username"] = $row["username"];
$post["email"] = $row["email"];
//update our repsonse JSON data
array_push($response["userInfo"], $post);
}
}
$result->free();
echo json_encode($response);
}
}
//Disconnect from the server
mysqli_close($con);
?>