<?php

// Get the user id
$user_id = isset($_REQUEST['user_id']) ? $_REQUEST['user_id'] : "";

// Database connection
$con = mysqli_connect("localhost", "infossel_info", "infossel123.", "infossel_dailyfinance");

// Check connection
if (mysqli_connect_errno()) {
    die("Failed to connect to MySQL: " . mysqli_connect_error());
}

if ($user_id !== "") {
    // Run the query
    $query = mysqli_query($con, "
        SELECT 
            name, pno, fname, pnoresi1, address, address1, address2, houserent, area, gg1, g2, lmark,
            nname, npno, naddress, naddress1, naddress2, npno1, nhouserent, narea, nlmark, ngg1, ng2
        FROM mcust 
        WHERE hpl = '$user_id'
    ");

    $row = mysqli_fetch_array($query);

    if ($row) {
        // Assign values
        $result = array(
            $row["name"],
            $row["pno"],
            $row["fname"],
            $row["pnoresi1"],
            $row["address"],
            $row["address1"],
            $row["address2"],
            $row["houserent"],
            $row["area"],
            $row["gg1"],
            $row["g2"],
            $row["lmark"],
            $row["nname"],
            $row["npno"],
            $row["naddress"],
            $row["naddress1"],
            $row["naddress2"],
            $row["npno1"],
            $row["nhouserent"],
            $row["narea"],
            $row["nlmark"],
            $row["ngg1"],
            $row["ng2"]
        );

        // Send JSON response
        echo json_encode($result);
    } else {
        echo json_encode(array("error" => "No record found"));
    }
} else {
    echo json_encode(array("error" => "Invalid user_id"));
}

mysqli_close($con);
?>
