<?php
session_start();

header("Access-Control-Allow-Origin: https://enerliths.com");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Headers: Content-Type");
header("Access-Control-Allow-Methods: POST, OPTIONS");
header("Content-Type: application/json");

if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
    http_response_code(200);
    exit();
}

require "../config/db.php";


$user_id = $_SESSION["user_id"];

$data = json_decode(file_get_contents("php://input"), true);

$name = $data["full_name"];

$stmt = $conn->prepare("UPDATE users SET full_name=? WHERE id=?");

$stmt->bind_param("si",$name,$user_id);

if($stmt->execute()){
    echo json_encode([
        "status"=>"success",
        "message"=>"Profile updated successfully"
    ]);
}else{
    echo json_encode([
        "status"=>"error",
        "message"=>"Unable to update profile"
    ]);
}