<?php
session_start();
header('Content-Type: application/json');
include_once("Connect.php");

$item_code = trim($_GET['item_code'] ?? '');

if ($item_code == "") {
    echo json_encode(array("exists" => false));
    exit();
}

$item_code = $mysqli->real_escape_string(htmlspecialchars($item_code, ENT_QUOTES));

$sql = "SELECT id
        FROM gold_sales
        WHERE item_code='$item_code'
          AND status='1'
        LIMIT 1";
$result = $mysqli->query($sql);

echo json_encode(array("exists" => ($result && $result->num_rows > 0)));
exit();
?>
