-
Notifications
You must be signed in to change notification settings - Fork 4
/
update-user.php
36 lines (33 loc) · 1.3 KB
/
update-user.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
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: access");
header("Access-Control-Allow-Methods: POST");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
require 'db_connection.php';
$data = json_decode(file_get_contents("php://input"));
if(isset($data->id)
&& isset($data->user_name)
&& isset($data->user_email)
&& is_numeric($data->id)
&& !empty(trim($data->user_name))
&& !empty(trim($data->user_email))
){
$username = mysqli_real_escape_string($db_conn, trim($data->user_name));
$useremail = mysqli_real_escape_string($db_conn, trim($data->user_email));
if (filter_var($useremail, FILTER_VALIDATE_EMAIL)) {
$updateUser = mysqli_query($db_conn,"UPDATE `users` SET `user_name`='$username', `user_email`='$useremail' WHERE `id`='$data->id'");
if($updateUser){
echo json_encode(["success"=>1,"msg"=>"User Updated."]);
}
else{
echo json_encode(["success"=>0,"msg"=>"User Not Updated!"]);
}
}
else{
echo json_encode(["success"=>0,"msg"=>"Invalid Email Address!"]);
}
}
else{
echo json_encode(["success"=>0,"msg"=>"Please fill all the required fields!"]);
}