<?php
// Database connection
include('connection.php');

// Check if the profile_id is provided
if (isset($_POST['profile_id'])) {
    $profile_id = $conn->real_escape_string($_POST['profile_id']);

    // Query to get objects based on profile_id
    $sql = "SELECT account_name FROM rr_410_accounts WHERE profile_id = '$profile_id'";
    $result = $conn->query($sql);

    $objects = array();
    
    // Fetch all objects and add them to the array
    if ($result->num_rows > 0) {
        while ($row = $result->fetch_assoc()) {
            $objects[] = $row['account_name'];
        }
    }
    
    // Return the objects as a JSON response
    echo json_encode($objects);
    error_log(json_encode($objects));
    $conn->close();
}
?>
