<?php
session_start();
require 'config.php';

if (!isset($_SESSION["user_id"])) {
    header("Location: login.php");
    exit;
}

$user_id = $_SESSION["user_id"];

$stmt = $conn->prepare("SELECT users.username, transactions.amount, transactions.timestamp FROM transactions JOIN users ON transactions.receiver_id = users.id WHERE transactions.sender_id = ? ORDER BY transactions.timestamp DESC");
$stmt->bind_param("i", $user_id);
$stmt->execute();
$stmt->bind_result($receiver, $amount, $timestamp);

echo "<h2>Transaktionshistorie</h2>";
echo "<table border='1'><tr><th>Empfänger</th><th>Betrag</th><th>Datum</th></tr>";
while ($stmt->fetch()) {
    echo "<tr><td>$receiver</td><td>$amount €</td><td>$timestamp</td></tr>";
}
echo "</table>";

$stmt->close();
$conn->close();
?>
<a href='dashboard.php'>Zurück</a>
