-
Welcome, User!
+Welcome, !
Wallet Balance
-R1,250.75
+R
Available Funds
Quick Actions
-
-
+ Send Money
+ Pay Merchant
Recent Transactions
exec("CREATE TABLE IF NOT EXISTS transactions ( id INT AUTO_INCREMENT PRIMARY KEY, + user_id INT NOT NULL, description VARCHAR(255) NOT NULL, amount DECIMAL(10, 2) NOT NULL, type VARCHAR(50) NOT NULL, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + notes TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (user_id) REFERENCES users(id) )"); - // Clear existing transactions and insert sample data for demonstration - $pdo->exec("TRUNCATE TABLE transactions"); - $transactions = [ - ['Payment to Shoprite', -120.50, 'Merchant Payment'], - ['Received from J. Doe', 250.00, 'P2P Transfer'], - ['Airtime Purchase (MTN)', -50.00, 'Bill Payment'], - ['Payment to Pick n Pay', -340.75, 'Merchant Payment'], - ['Received from A. Smith', 500.00, 'P2P Transfer'], - ]; - $stmt = $pdo->prepare("INSERT INTO transactions (description, amount, type) VALUES (?, ?, ?)"); - foreach ($transactions as $tx) { - $stmt->execute($tx); - } - - - // Fetch transactions - $stmt = $pdo->query("SELECT description, amount, type, created_at FROM transactions ORDER BY created_at DESC"); + // Fetch transactions for the logged-in user + $stmt = $pdo->prepare("SELECT description, amount, type, notes, created_at FROM transactions WHERE user_id = :user_id ORDER BY created_at DESC LIMIT 10"); + $stmt->execute(['user_id' => $user_id]); $transactions = $stmt->fetchAll(); if (count($transactions) > 0) { @@ -112,6 +129,9 @@ echo ''; echo '' . htmlspecialchars($tx['description']) . ''; echo '' . htmlspecialchars($tx['type']) . ''; + if (!empty($tx['notes'])) { + echo '' . htmlspecialchars($tx['notes']) . ''; + } echo 'No recent transactions.
'; } } catch (PDOException $e) { - echo 'Database error: ' . htmlspecialchars($e->getMessage()) . '
'; + echo 'Database error: Could not fetch transactions.
'; } ?> @@ -136,4 +156,4 @@ - +