We've created an in-depth car rental database that stores a variety of information. A very simple PHP application is connected to our database and displays the car rental company's branch revenues.
- A customer can have zero or many reservations.
- A reservation can be booked by only one customer.
- A vehicle can have zero or may reservations.
- A reservation includes only one vehicle.
- A rental can have one or many reservations.
- A reservation contains only one rental.
- A branch can provide many vehicles.
- A vehicle can be reserved from one branch.
- A vehicle can be dropped off at any branch.
- An employee can only be assigned to one branch.
- A branch can have many employees.
- A manager can manage one branch.
- A branch has only one manager.
- An Employee can handle zero or many reservations.
- A reservation is processed by only one employee.
- An insurance is provided to zero or many rentals.
- A rental can have zero or one insurance.
- A reservation can have many addon products.
- An addon product can be in many reservations.
- A payment belongs to one reservation.
- A Vehicle can be of any type (Sedan, SUV, Van etc.).
- A rental can have many inspections.
- There are Multiple branches of the rental company.
- Customers can make reservations in advanced or on the same day.
- A customer must be registered to make a reservation.
- Vehicles can be returned to either the same or different branch.
- Vehicles should be checked/inspected before and after rental.
- Any damages that are made are to be charged to the customer’s card if they have no insurance.
- Customer must have insurance or add insurance policy at the checkout desk.
The application is very simple. It simply allows us to see what the revenues are for any branches we select.
This is an image showing how the application looks before any selections are made. It also features a clear button to clear selections.
Now, the user has selected the branches they would like to view the revenues for. The user simply needs to click the Submit button to proceed.
Now, let's take a deeper look at the code.
- Line 54 is using JavaScript to incorporate a ‘Select All’ button
- Line 68 tells the information where to go after the Submit button is pressed
- Checkboxes are defined under the name ‘branch[]’
All the branch revenues are now shown.
Now, let's take a deeper look at the code.
- Line 83 – Gathers the POST information from home.php and puts it into an array
- Line 85 – Separates contents of the array with ‘ , ‘ between
- Line 87 – The database query is defined
- Line 92- Each Branch selection from home.php is put into the Where In statement
- Line 97- Connects to the database with error handling
- Line 101- Put the results from the database query into a table
- Line 113- JavaScript that makes the ‘Restart’ button go back to home.php