Car Rental Php Script Info

$check_result = mysqli_query($conn, $check_sql);

<div class="container mt-4"> <h2>My Bookings</h2> <?php if(mysqli_num_rows($result) > 0): ?> <div class="table-responsive"> <table class="table table-bordered table-hover"> <thead class="table-dark"> <tr> <th>Booking ID</th> <th>Car</th> <th>License Plate</th> <th>Pickup Date</th> <th>Return Date</th> <th>Total Days</th> <th>Total Price</th> <th>Status</th> <th>Payment Status</th> <th>Action</th> </tr> </thead> <tbody> <?php while($booking = mysqli_fetch_assoc($result)): ?> <tr> <td>#<?php echo $booking['id']; ?></td> <td><?php echo $booking['brand'] . ' ' . $booking['model']; ?></td> <td><?php echo $booking['license_plate']; ?></td> <td><?php echo date('d M Y', strtotime($booking['pickup_date'])); ?></td> <td><?php echo date('d M Y', strtotime($booking['return_date'])); ?></td> <td><?php echo $booking['total_days']; ?></td> <td>$<?php echo number_format($booking['total_price'], 2); ?></td> <td> <span class="badge bg-<?php echo $booking['status'] == 'confirmed' ? 'success' : ($booking['status'] == 'pending' ? 'warning' : ($booking['status'] == 'cancelled' ? 'danger' : 'info')); ?>"> <?php echo ucfirst($booking['status']); ?> </span> </td> <td> <span class="badge bg-<?php echo $booking['payment_status'] == 'paid' ? 'success' : 'warning'; ?>"> <?php echo ucfirst($booking['payment_status']); ?> </span> </td> <td> <?php if($booking['status'] == 'pending' && $booking['payment_status'] == 'pending'): ?> <a href="payment.php?booking_id=<?php echo $booking['id']; ?>" class="btn btn-sm btn-primary">Pay Now</a> <a href="cancel-booking.php?id=<?php echo $booking['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure?')">Cancel</a> <?php endif; ?> </td> </tr> <?php endwhile; ?> </tbody> </table> </div> <?php else: ?> <div class="alert alert-info">No bookings found.</div> <?php endif; ?> </div> </body> </html> <?php session_start(); session_destroy(); header("Location: index.php"); exit(); ?> This complete car rental system includes:

-- Bookings table CREATE TABLE bookings ( id INT PRIMARY KEY AUTO_INCREMENT, user_id INT, car_id INT, pickup_date DATE NOT NULL, return_date DATE NOT NULL, total_days INT, total_price DECIMAL(10,2), status ENUM('pending', 'confirmed', 'active', 'completed', 'cancelled') DEFAULT 'pending', payment_status ENUM('pending', 'paid', 'refunded') DEFAULT 'pending', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, FOREIGN KEY (car_id) REFERENCES cars(id) ON DELETE CASCADE ); car rental php script

// Function to display messages function showMessage($msg, $type = 'success') return "<div class='alert alert-$type alert-dismissible fade show' role='alert'> $msg <button type='button' class='btn-close' data-bs-dismiss='alert'></button> </div>";

// Create connection $conn = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); 'success' : ($booking['status'] == 'pending'

// Calculate days and price $pickup = new DateTime($pickup_date); $return = new DateTime($return_date); $interval = $pickup->diff($return); $total_days = $interval->days + 1; $total_price = $total_days * $car['price_per_day'];

$car_id = isset($_GET['id']) ? (int)$_GET['id'] : 0; 'success' : 'warning';

?>

$check_result = mysqli_query($conn, $check_sql);

<div class="container mt-4"> <h2>My Bookings</h2> <?php if(mysqli_num_rows($result) > 0): ?> <div class="table-responsive"> <table class="table table-bordered table-hover"> <thead class="table-dark"> <tr> <th>Booking ID</th> <th>Car</th> <th>License Plate</th> <th>Pickup Date</th> <th>Return Date</th> <th>Total Days</th> <th>Total Price</th> <th>Status</th> <th>Payment Status</th> <th>Action</th> </tr> </thead> <tbody> <?php while($booking = mysqli_fetch_assoc($result)): ?> <tr> <td>#<?php echo $booking['id']; ?></td> <td><?php echo $booking['brand'] . ' ' . $booking['model']; ?></td> <td><?php echo $booking['license_plate']; ?></td> <td><?php echo date('d M Y', strtotime($booking['pickup_date'])); ?></td> <td><?php echo date('d M Y', strtotime($booking['return_date'])); ?></td> <td><?php echo $booking['total_days']; ?></td> <td>$<?php echo number_format($booking['total_price'], 2); ?></td> <td> <span class="badge bg-<?php echo $booking['status'] == 'confirmed' ? 'success' : ($booking['status'] == 'pending' ? 'warning' : ($booking['status'] == 'cancelled' ? 'danger' : 'info')); ?>"> <?php echo ucfirst($booking['status']); ?> </span> </td> <td> <span class="badge bg-<?php echo $booking['payment_status'] == 'paid' ? 'success' : 'warning'; ?>"> <?php echo ucfirst($booking['payment_status']); ?> </span> </td> <td> <?php if($booking['status'] == 'pending' && $booking['payment_status'] == 'pending'): ?> <a href="payment.php?booking_id=<?php echo $booking['id']; ?>" class="btn btn-sm btn-primary">Pay Now</a> <a href="cancel-booking.php?id=<?php echo $booking['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure?')">Cancel</a> <?php endif; ?> </td> </tr> <?php endwhile; ?> </tbody> </table> </div> <?php else: ?> <div class="alert alert-info">No bookings found.</div> <?php endif; ?> </div> </body> </html> <?php session_start(); session_destroy(); header("Location: index.php"); exit(); ?> This complete car rental system includes:

-- Bookings table CREATE TABLE bookings ( id INT PRIMARY KEY AUTO_INCREMENT, user_id INT, car_id INT, pickup_date DATE NOT NULL, return_date DATE NOT NULL, total_days INT, total_price DECIMAL(10,2), status ENUM('pending', 'confirmed', 'active', 'completed', 'cancelled') DEFAULT 'pending', payment_status ENUM('pending', 'paid', 'refunded') DEFAULT 'pending', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, FOREIGN KEY (car_id) REFERENCES cars(id) ON DELETE CASCADE );

// Function to display messages function showMessage($msg, $type = 'success') return "<div class='alert alert-$type alert-dismissible fade show' role='alert'> $msg <button type='button' class='btn-close' data-bs-dismiss='alert'></button> </div>";

// Create connection $conn = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);

// Calculate days and price $pickup = new DateTime($pickup_date); $return = new DateTime($return_date); $interval = $pickup->diff($return); $total_days = $interval->days + 1; $total_price = $total_days * $car['price_per_day'];

$car_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;

?>