<?php
session_start();
include '../db_connect.php';

if (!isset($_SESSION['user_id'])) {
    header("Location: login.php");
    exit();
}

if (isset($_POST['update'])) {
    $user_id = $_SESSION['user_id'];
    $name = mysqli_real_escape_string($conn, $_POST['name']);
    $email = mysqli_real_escape_string($conn, $_POST['email']);
    $mobile = mysqli_real_escape_string($conn, $_POST['mobile']);

    $query = "UPDATE users SET name='$name', email='$email', mobile='$mobile' WHERE id='$user_id'";
    if (mysqli_query($conn, $query)) {
        $_SESSION['user_name'] = $name; // update session name
        header("Location: ../frontend/account.php?success=1");
        exit();
    } else {
        echo "Error updating record: " . mysqli_error($conn);
    }
}
?>
