-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.php
50 lines (45 loc) · 1.62 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
<?php
require 'config.php';
include("session.php");
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$dob = mysqli_real_escape_string($db, $_POST['dob']);
$name = mysqli_real_escape_string($db, $_POST['name']);
$age = mysqli_real_escape_string($db, $_POST['age']);
$phone = mysqli_real_escape_string($db, $_POST['phone']);
$gender = mysqli_real_escape_string($db, $_POST['gender']);
$address = mysqli_real_escape_string($db, $_POST['address']);
$file_name = $_FILES['photo']['name'];
$file_tmp = $_FILES['photo']['tmp_name'];
$ext = pathinfo($file_name, PATHINFO_EXTENSION);
$file_name = $name . "." . $ext;
$filePath = "img/profile/" . $file_name;
// Check if the file was uploaded successfully
if (move_uploaded_file($file_tmp, $filePath)) {
// File moved successfully
$query = "UPDATE detail SET photo='$filePath',name='$name', age='$age', dob='$dob', phone='$phone',address='$address',gender='$gender' WHERE email='$s'";
$query_run = mysqli_query($db, $query);
if ($query_run) {
$res = [
'status' => 200,
'message' => 'Profile Updated Successfully'
];
echo json_encode($res);
return;
}
} else {
// File move failed
$res = [
'status' => 500,
'message' => 'Failed to move uploaded file'
];
echo json_encode($res);
return;
}
} else {
$res = [
'status' => 500,
'message' => 'Failed to Update Profile'
];
echo json_encode($res);
}
?>