<?php

include "../classes/db.class.php";
$db = new db();

$otp = $_POST['otp'];
// hash otp 
$otp_hash = hash("sha256", $otp);
// checkn db for hash with email:
$res = $db->query("SELECT * FROM otp WHERE otp = '$otp_hash' AND email = '$_POST[email]'");
if ($res->num_rows > 0) {
    $db->query("DELETE FROM otp WHERE date_time <= NOW() - INTERVAL 1 MINUTE");
    echo 1;
} else {
    $db->query("DELETE FROM otp WHERE date_time <= NOW() - INTERVAL 1 MINUTE");
    echo 0;
}