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

include_once 'connect.php';

$response = ['success' => false, 'school_name' => ''];

if (isset($_POST['emis_code']) && strlen($_POST['emis_code']) === 11) {
    $emisCode = $conn->real_escape_string($_POST['emis_code']);
    
    $sql = "SELECT school_name FROM school_emis WHERE emis_code = '$emisCode' LIMIT 1";
    $result = $conn->query($sql);
    
    if ($result && $result->num_rows > 0) {
        $row = $result->fetch_assoc();
        $response = [
            'success' => true,
            'school_name' => htmlspecialchars($row['school_name'])
        ];
    }
}

echo json_encode($response);
$conn->close();
?>