<?php
/* =========================
   SESSION & KONEKSI
========================= */
session_start();
error_reporting(E_ALL);
ini_set('display_errors', 1);

$conn = mysqli_connect("localhost","USERNAME_DB","PASSWORD_DB","NAMA_DB");

if (!$conn) {
    die("Koneksi database gagal: " . mysqli_connect_error());
}

/* =========================
   CEK LOGIN
========================= */
if (!isset($_SESSION['user'])) {
    header("Location: /");
    exit;
}

$username = mysqli_real_escape_string($conn, $_SESSION['user']);
$query = mysqli_query($conn, "SELECT * FROM tb_user WHERE username='$username'");
$user = mysqli_fetch_assoc($query);

?>
<!DOCTYPE html>
<html>
<head>
    <title>Profile</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>

<div class="container mt-4">
    <h4>Profile User</h4>
    <hr>

    <p><b>Username:</b> <?php echo $user['username']; ?></p>
    <p><b>Email:</b> <?php echo $user['email']; ?></p>
    <p><b>Saldo:</b> Rp <?php echo number_format($user['saldo']); ?></p>

    <hr>
    <a href="change-password.php" class="btn btn-primary btn-block">Ubah Kata Sandi</a>
</div>

</body>
</html>