<?php
require_once "config.php";
$response = ["success"=>false,"message"=>"Invalid request"];

if($_SERVER["REQUEST_METHOD"] === "POST"){
    $enquiry_id = $_POST['enquiry_id'] ?? 0;
    $otp = $_POST['otp'] ?? '';

    $stmt = $pdo->prepare("SELECT otp FROM gate_enquiries WHERE enquiry_id=?");
    $stmt->execute([$enquiry_id]);
    $row = $stmt->fetch();

    if($row && $row['otp'] == $otp){
        $pdo->prepare("UPDATE gate_enquiries SET otp_verified=1 WHERE enquiry_id=?")->execute([$enquiry_id]);
        $response = ["success"=>true,"message"=>"OTP verified successfully!"];
    } else {
        $response = ["success"=>false,"message"=>"Invalid OTP. Try again."];
    }
}
echo json_encode($response);
