-
Notifications
You must be signed in to change notification settings - Fork 2
/
edit_profile.php
56 lines (46 loc) · 1.62 KB
/
edit_profile.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
<?php
include("dbconnection.php");
$con = dbconnection();
$response = ['success' => 'false'];
if (isset($_POST["email"], $_POST["password"], $_POST["new_fname"], $_POST["new_lname"])) {
$email = trim($_POST["email"]);
$password = trim($_POST["password"]);
$newFname = trim($_POST["new_fname"]);
$newLname = trim($_POST["new_lname"]);
// Validate email
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$response['message'] = 'Invalid email format';
echo json_encode($response);
exit;
}
// Check if the email and password match
$stmt = $con->prepare("SELECT upassword FROM sign_up WHERE uemail = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->bind_result($storedPassword);
$stmt->fetch();
$stmt->close();
if ($storedPassword) {
// Verify password
if ($password === $storedPassword) {
// Update user profile data
$stmt = $con->prepare("UPDATE sign_up SET ufname = ?, ulname = ? WHERE uemail = ?");
$stmt->bind_param("sss", $newFname, $newLname, $email);
if ($stmt->execute()) {
$response['success'] = 'true';
$response['message'] = 'Profile updated successfully';
} else {
$response['message'] = 'Profile update failed: ' . $stmt->error;
}
$stmt->close();
} else {
$response['message'] = 'Invalid password';
}
} else {
$response['message'] = 'Email not found';
}
} else {
$response['message'] = 'Required fields are missing';
}
echo json_encode($response);
?>