<?php
include '../db.php'; // Include database connection
if (isset($_POST['country_id'])) {
    $country_id = mysqli_real_escape_string($con, $_POST['country_id']);
    $sql = "SELECT id, name FROM state WHERE country_id = '$country_id' ORDER BY name ASC";
    $res = mysqli_query($con, $sql);
    while ($row = mysqli_fetch_assoc($res)) {
        echo "<option data-id='{$row['id']}' value='{$row['name']}'>{$row['name']}</option>";
    }
}
?>