<?php
// Include the database connection file
require_once 'connection.php';

// Check if email parameter is provided
if (isset($_GET['email'])) {
    $email = trim($_GET['email']);
    // Fetch user from the database by email
// Fetch user from the database by email
$sql = "SELECT * FROM user WHERE email = '$email'";
    $result = $conn->query($sql);

    if ($result->num_rows > 0) {
        $row = $result->fetch_assoc();
        // Prepare user data
        $user = array(
            "id" => $row['id'],
            "name" => $row['name'],
            "email" => $row['email'],
            "image" => $row['image'],
            "fcm" => $row['fcm']
            // Add more fields as needed
        );
        // Success response with the user data
        $response = array(
            "status" => "success",
            "user" => $user
        );
    } else {
        // No user found
        $response = array(
            "status" => "error",
            "message" => "User not found with email: $email"
        );
    }
} else {
    // No email parameter provided
    $response = array(
        "status" => "error",
        "message" => "Email parameter is required"
    );
}

header('Content-Type: application/json');
echo json_encode($response);

$conn->close();
?>
