<?php
header('Content-Type: application/json');
include('../connection.php');
$conn->set_charset("utf8mb4");
if(isset($_POST['id'])) {
    $id = $_POST['id'];
    
    // Prepare the SQL statement to get user data by ID
    $stmt = $conn->prepare("SELECT * FROM marketing WHERE id = ? LIMIT 1");
    $stmt->bind_param("i", $id); // Assuming ID is an integer
    $stmt->execute();
    $result = $stmt->get_result();
    
    if ($row = $result->fetch_assoc()) {
        $data= [
            'id' => $row['id'],
            'name' => $row['name'],
            'username' => $row['username'],
            'address' => $row['address'],
            'phone' => $row['phone'],
            'move_charge' => $row['move_charge'],
            'final_connection_charge' => $row['final_connection_charge'],
            'cable_length' => $row['cable_length'],
            'final_cable' => $row['final_cable'],
            'cable_code' => $row['cable_code'],
            'final_length' => $row['final_length'],
            'sender_id' => $row['sender_id'],
            'expected_time' => $row['expected_time'],
            'remark' => $row['remark'],
            'referby' => $row['referby'],
            'reference' => $row['reference']
        ];
    } else {
        // User not found, prepare error data
        $data = [
            'status' => 'error',
            'message' => 'Data not found with the provided ID!'
        ];
    }
    $jsonData = json_encode($data);
    echo $jsonData;

    // Close the statement
    $stmt->close();
} else {
    // No data found
    $data = [
        'status' => 'error',
        'message' => 'No data provided!'
    ];

    $jsonData = json_encode($data);
    echo $jsonData;
}
?>