<?php
require_once __DIR__ . '/../../connect.php';

$phone_number = $encryptionHelper->encryptData(filterRequest("phone_number"));
$token_code = $encryptionHelper->encryptData(filterRequest("token"));

//  error_log("phone=$phone_number, token=$token_code");

// Check if the phone number and token code match
$sql = "SELECT * FROM `phone_verification_passenger` WHERE `phone_number` = '$phone_number' AND `token` = '$token_code' 
AND `verified` = 0 ";
// error_log("sql is =$sql");

$stmt = $con->prepare($sql);
$stmt->execute();
$result = $stmt->fetch();

if ($result) {
    // $id = $result["id"];
    $sql = "UPDATE `phone_verification_passenger` SET `verified` = 1 WHERE `phone_number` = '$phone_number'";
    $stmt = $con->prepare($sql);
    $stmt->execute();

    jsonSuccess($message = "Your phone number has been verified.");
} else {
    jsonError($message = "Your phone number could not be verified. Please try again.");
}
?>