<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include("conn.php");  // DB connection file

if (!isset($_GET['userid'])) {
    die("User ID missing");
}

$userid = (int) $_GET['userid'];

// Prepare query
$sql = "SELECT amount, orderid, status, created_at FROM recharge WHERE uid = ? ORDER BY created_at DESC LIMIT 25";

if ($stmt = $conn->prepare($sql)) {
    $stmt->bind_param("i", $userid);
    $stmt->execute();
    $result = $stmt->get_result();

    if ($result->num_rows > 0) {
        echo "<table border='1' cellpadding='5' cellspacing='0'>";
        echo "<tr><th>Order ID</th><th>Amount</th><th>Status</th><th>Date</th></tr>";
        while ($row = $result->fetch_assoc()) {
            echo "<tr>";
            echo "<td>" . htmlspecialchars($row['orderid']) . "</td>";
            echo "<td>" . htmlspecialchars($row['amount']) . "</td>";
            echo "<td>" . htmlspecialchars($row['status']) . "</td>";
            echo "<td>" . htmlspecialchars($row['created_at']) . "</td>";
            echo "</tr>";
        }
        echo "</table>";
    } else {
        echo "No recharge history found for user ID: $userid";
    }
    $stmt->close();
} else {
    echo "Database query error: " . $conn->error;
}

$conn->close();
?>
