Files
4WDCSA.co.za/src/processors/update_user.php

43 lines
1.5 KiB
PHP

<?php
$rootPath = dirname(dirname(__DIR__));
require_once($rootPath . "/src/config/env.php");
require_once($rootPath . "/src/config/session.php");
require_once($rootPath . "/src/config/connection.php");
require_once($rootPath . "/src/config/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);