| Server IP : 139.59.63.204 / Your IP : 216.73.217.62 Web Server : Apache/2.4.58 (Ubuntu) System : Linux ubuntu-s-1vcpu-1gb-blr1-01 6.8.0-110-generic #110-Ubuntu SMP PREEMPT_DYNAMIC Thu Mar 19 15:09:20 UTC 2026 x86_64 User : root ( 0) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/abyogasms.com/html/iyd/ |
Upload File : |
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
function db_connect(): PDO {
$dsn = 'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8mb4';
$pdo = new PDO($dsn, DB_USER, DB_PASS, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);
return $pdo;
}
// Set headers to return clean JSON data
header('Content-Type: application/json');
// Ensure you only run this if a state ID is provided
if (isset($_GET['state_id'])) {
$state_id = $_GET['state_id'];
// Assuming your db_connect function is accessible here
// require_once 'db.php';
require_once("config.php");
$pdo = db_connect();
// Use prepared statements to prevent SQL injection
$stmt = $pdo->prepare("SELECT id, district_name FROM districts WHERE state_id = :state_id");
$stmt->execute(['state_id' => $state_id]);
$districts = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Convert the database array directly into a JSON string
echo json_encode($districts);
exit;
}
// Return an empty array if no ID was provided
echo json_encode([]);