prepare("SELECT * FROM cars WHERE id = ? AND status = 'Available' AND is_deleted = 0 LIMIT 1"); $stmt->execute([$car_id]); $car = $stmt->fetch(); if (!$car) { echo "

Not Available

This car is no longer available for purchase.

Back to Marketplace
"; require_once __DIR__ . '/includes/footer.php'; exit; } $success = false; $error = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $bank = $_POST['bank'] ?? ''; $account = $_POST['account'] ?? ''; if (empty($bank) || empty($account)) { $error = "Please fill in all simulation details."; } else { // Start simulated transaction try { $db->beginTransaction(); // 1. Record Purchase $pStmt = $db->prepare("INSERT INTO purchases (user_id, car_id, bank_name, transaction_id, amount) VALUES (?, ?, ?, ?, ?)"); $trans_id = "AFG-" . strtoupper(uniqid()); $pStmt->execute([$_SESSION['user_id'], $car_id, $bank, $trans_id, $car['price']]); // 2. Update Car Status $uStmt = $db->prepare("UPDATE cars SET status = 'SOLD' WHERE id = ?"); $uStmt->execute([$car_id]); // 3. Create Notification $nStmt = $db->prepare("INSERT INTO notifications (user_id, title, message) VALUES (?, ?, ?)"); $nStmt->execute([$_SESSION['user_id'], "Purchase Successful", "Congratulations! You have successfully reserved " . $car['title'] . ". Transaction ID: " . $trans_id]); $db->commit(); $success = true; } catch (Exception $e) { $db->rollBack(); $error = "Simulation error: " . $e->getMessage(); } } } ?>
🎉

Purchase Successful!

Your simulated payment has been processed. The car is now reserved in your name.

Transaction ID:

Amount: $

Go to My Dashboard

Bank Payment Simulation

Secure Offline Transaction System

Car
Price $

Enter any mock account number for this demonstration.

Cancel
🔒 This is an offline simulation. No real money will be transferred.