<?php
@session_start();
include('config.php'); // your DB connection

header('Content-Type: application/json');

if(!isset($_SESSION['phone'])){
    echo json_encode(['title'=>'Error','text'=>'User not logged in','status'=>false]);
    exit;
}

if(isset($_POST['curpass'], $_POST['npass'], $_POST['cpass'])){
    $curpass = $_POST['curpass'];
    $npass = $_POST['npass'];
    $cpass = $_POST['cpass'];

    // call your function
    $result = change_password($tng_conn, $_SESSION['phone'], $curpass, $npass, $cpass);

    echo json_encode([
        'title' => $result['title'],
        'text'  => $result['text'],
        'status'=> $result['status']
    ]);
} else {
    echo json_encode(['title'=>'Error','text'=>'All fields are required','status'=>false]);
}
?>
