<?php
include('includes/config.php');

if (isset($_POST['accession_no'])) {
    $acc_no = trim($_POST['accession_no']);

    $sql = "SELECT COUNT(*) FROM tblbookcopies WHERE accession_no = :acc_no";
    $query = $dbh->prepare($sql);
    $query->bindParam(':acc_no', $acc_no, PDO::PARAM_STR);
    $query->execute();
    $count = $query->fetchColumn();

    echo json_encode(['exists' => $count > 0]);
}
?>
