40 lines
1.3 KiB
PHP
40 lines
1.3 KiB
PHP
<?php
|
|
require_once("session.php");
|
|
require_once("connection.php");
|
|
require_once("functions.php");
|
|
|
|
$response = array('status' => 'error', 'message' => 'Something went wrong');
|
|
|
|
// Check if the user is logged in
|
|
if (!isset($_SESSION['user_id'])) {
|
|
$response['message'] = 'You are not logged in.';
|
|
echo json_encode($response);
|
|
exit();
|
|
}
|
|
|
|
$user_id = $_SESSION['user_id'];
|
|
|
|
// Handle updating user details (excluding profile picture)
|
|
if (isset($_POST['first_name'], $_POST['last_name'], $_POST['phone_number'], $_POST['email'])) {
|
|
$first_name = ucwords(strtolower($_POST['first_name']));
|
|
$last_name = ucwords(strtolower($_POST['last_name']));
|
|
$phone_number = $_POST['phone_number'];
|
|
$email = $_POST['email'];
|
|
|
|
// Update user details in the database
|
|
$sql = "UPDATE users SET first_name = ?, last_name = ?, phone_number = ?, email = ? WHERE user_id = ?";
|
|
$stmt = $conn->prepare($sql);
|
|
$stmt->bind_param("ssssi", $first_name, $last_name, $phone_number, $email, $user_id);
|
|
|
|
if ($stmt->execute()) {
|
|
$response['status'] = 'success';
|
|
$response['message'] = 'User details updated successfully';
|
|
} else {
|
|
$response['message'] = 'Failed to update user details';
|
|
}
|
|
} else {
|
|
$response['message'] = 'Invalid form submission';
|
|
}
|
|
|
|
echo json_encode($response);
|