<?php
// Include database connection
include '../config/db.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $drug_name = htmlspecialchars($_POST['drug_name']);

    // Check if the drug exists in the database
    $stmt = $pdo->prepare("SELECT id FROM drugs WHERE drug_name = ?");
    $stmt->execute([$drug_name]);
    $drug = $stmt->fetch();

    if ($drug) {
        echo json_encode(['exists' => true, 'id' => $drug['id']]);
        
    } else {
        echo json_encode(['exists' => false]);
    }
}
?>
