| Linux premium274.web-hosting.com 4.18.0-553.45.1.lve.el8.x86_64 #1 SMP Wed Mar 26 12:08:09 UTC 2025 x86_64 Path : /home/whagcoha/ledger.mwagalwaservices.com/ |
| Current File : /home/whagcoha/ledger.mwagalwaservices.com/savings.php |
<?php
if ((!isset($_SESSION['gen256'])) ) {
echo "<script>
window.open('login.php','_self');
</script>";
}
?>
<?php
$user_id = $_SESSION['gen256']['id'] ?? null;
if (!$user_id) {
die("User not logged in");
}
// Fetch savings (only where saving = 1)
$savings = [];
$stmt = $conn->prepare("SELECT category, amount, date, notes
FROM expenses
WHERE user_id = ? AND saving = 1
ORDER BY date DESC");
$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
$savings[] = $row;
}
$stmt->close();
?>
<div class="container mt-5">
<h2 class="mb-4">My Savings</h2>
<?php if (count($savings) === 0): ?>
<div class="alert alert-info">No savings found.</div>
<?php else: ?>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>Category Desc</th>
<th>Amount</th>
<th>Date</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<?php foreach ($savings as $i => $saving): ?>
<tr>
<td><?= $i + 1 ?></td>
<td><?= htmlspecialchars($saving['category']) ?></td>
<td><?= number_format($saving['amount'], 2) ?></td>
<td><?= htmlspecialchars($saving['date']) ?></td>
<td><?= htmlspecialchars($saving['notes']) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</div>