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

try {
    $stmt = $dbh->query("SELECT id, name FROM states ORDER BY name ASC");
    $states = $stmt->fetchAll(PDO::FETCH_ASSOC);

    echo json_encode($states);
} catch (PDOException $e) {
    http_response_code(500);
    echo json_encode(['error' => 'Database error: ' . $e->getMessage()]);
}
