Car Rental Php Script <2024>

<footer class="bg-dark text-white text-center py-3 mt-5"> <p>© 2024 <?php echo SITE_NAME; ?>. All rights reserved.</p> </footer>

$error = '';

<h2 class="mb-4">Available Cars</h2> <div class="row"> <?php if(mysqli_num_rows($result) > 0): ?> <?php while($car = mysqli_fetch_assoc($result)): ?> <div class="col-md-4 mb-4"> <div class="card h-100 shadow-sm"> <?php if($car['image']): ?> <img src="uploads/<?php echo $car['image']; ?>" class="card-img-top" alt="<?php echo $car['brand'] . ' ' . $car['model']; ?>" style="height: 200px; object-fit: cover;"> <?php else: ?> <div class="bg-secondary text-white text-center py-5"> <i class="fas fa-car fa-3x"></i> </div> <?php endif; ?> <div class="card-body"> <h5 class="card-title"><?php echo $car['brand'] . ' ' . $car['model'] . ' (' . $car['year'] . ')'; ?></h5> <p class="card-text"> <i class="fas fa-chair"></i> <?php echo $car['seats']; ?> Seats | <i class="fas fa-cog"></i> <?php echo $car['transmission']; ?> | <i class="fas fa-gas-pump"></i> <?php echo $car['fuel_type']; ?> </p> <p class="card-text"> <strong>License Plate:</strong> <?php echo $car['license_plate']; ?><br> <strong>Color:</strong> <?php echo $car['color']; ?> </p> <h4 class="text-primary">$<?php echo number_format($car['price_per_day'], 2); ?>/day</h4> </div> <div class="card-footer bg-transparent"> <?php if(isLoggedIn()): ?> <a href="book-car.php?id=<?php echo $car['id']; ?>" class="btn btn-primary w-100">Book Now</a> <?php else: ?> <a href="login.php" class="btn btn-primary w-100">Login to Book</a> <?php endif; ?> </div> </div> </div> <?php endwhile; ?> <?php else: ?> <div class="col-12"> <div class="alert alert-info">No cars available at the moment.</div> </div> <?php endif; ?> </div> </div>

if ($_SERVER['REQUEST_METHOD'] == 'POST') $pickup_date = $_POST['pickup_date']; $return_date = $_POST['return_date']; car rental php script

<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:

$error = ''; $success = '';

// Create connection $conn = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); $car['model'];

<div class="container mt-4"> <div class="hero-section bg-primary text-white text-center py-5 mb-4 rounded"> <h1>Welcome to Car Rental System</h1> <p>Find the perfect car for your journey at affordable prices</p> </div>

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>My Bookings - <?php echo SITE_NAME; ?></title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <?php include 'navbar.php'; ?>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script> </body> </html> <?php require_once 'config.php'; if (!isLoggedIn()) redirect('login.php'); ?php echo ucfirst($booking['status'])

-- Cars table CREATE TABLE cars ( id INT PRIMARY KEY AUTO_INCREMENT, brand VARCHAR(50) NOT NULL, model VARCHAR(50) NOT NULL, year INT, license_plate VARCHAR(20) UNIQUE NOT NULL, color VARCHAR(30), seats INT DEFAULT 5, transmission ENUM('Manual', 'Automatic') DEFAULT 'Manual', fuel_type ENUM('Petrol', 'Diesel', 'Electric', 'Hybrid') DEFAULT 'Petrol', price_per_day DECIMAL(10,2) NOT NULL, image VARCHAR(255), status ENUM('available', 'rented', 'maintenance') DEFAULT 'available', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP );

// Get car details $sql = "SELECT * FROM cars WHERE id = $car_id AND status = 'available'"; $result = mysqli_query($conn, $sql);