<?php
header('Content-Type: application/json');
include 'connect.php';

$personal_no = $_GET['personal_no'] ?? '';

// Validate input is exactly 8 digits
if (!preg_match('/^\d{8}$/', $personal_no)) {
    die(json_encode(['exists' => false]));
}

// Use the correct column name personal_no
$stmt = $conn->prepare("SELECT 1 FROM employees WHERE personal_no = ? LIMIT 1");
$stmt->bind_param("s", $personal_no);
$stmt->execute();
$exists = $stmt->fetch();

echo json_encode(['exists' => $exists]);

$stmt->close();
$conn->close();
?>