<?php

require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include ('includes/function.php');

$zdb = $_SESSION["zdbyear_$dbname"];
mysqli_select_db($conn, $zdb);

if ($_REQUEST["country"]) {
    $count = $_REQUEST["country"];
    
    if ($_REQUEST["para"] == "state") {

        $getcons1 = mysqli_query($conn, "SELECT `code`, `name` FROM `state` Where country = '$count'") or die(mysqli_error($conn));
        
        echo "<option value=''>Select State</option>";
        while ($row = mysqli_fetch_array($getcons1)) {           
            echo "<option value='$row[code]'>$row[name]</option>";
        }
    }
}
if ($_REQUEST["state"]) {
    $state = $_REQUEST["state"];
    
    if ($_REQUEST["para2"] == "dist") {

        $getcons1 = mysqli_query($conn, "SELECT `code`, `name` FROM `district` Where state = '$state'") or die(mysqli_error($conn));
        
        echo "<option value=''>Select District</option>";
        while ($row = mysqli_fetch_array($getcons1)) {           
            echo "<option value='$row[code]'>$row[name]</option>";
        }
    }
}
if ($_REQUEST["dist"]) {
    $dist = $_REQUEST["dist"];
    
    if ($_REQUEST["para3"] == "tehsil") {

        $getcons1 = mysqli_query($conn, "SELECT `code`, `name` FROM `tehsil` Where district = '$dist'") or die(mysqli_error($conn));
        
        echo "<option value=''>Select Tehsil</option>";
        while ($row = mysqli_fetch_array($getcons1)) {           
            echo "<option value='$row[code]'>$row[name]</option>";
        }
    }
}
if ($_REQUEST["teh"]) {
    $teh = $_REQUEST["teh"];
    
    if ($_REQUEST["para4"] == "city") {

        $getcons1 = mysqli_query($conn, "SELECT `code`, `name` FROM `city` Where tehsil = '$teh'") or die(mysqli_error($conn));
        
        echo "<option value=''>Select City</option>";
        while ($row = mysqli_fetch_array($getcons1)) {           
            echo "<option value='$row[code]'>$row[name]</option>";
        }
    }
}
?>
