I'm trying to compare two dates on for the start of the rent and the end of the rent but with a database where some vehicles could have already rented at thoses dates
i've already have a code that block the user to book a car between two dates but after that it's still blocked
if( empty($content) ){
extract($_POST); // here i extract my _post
if( !empty($idmembre) ){
$vehicule = execReq( "SELECT * FROM vehicule WHERE idvehicule=:idvehicule", array(
'idvehicule' => $idvehicule
));
$infoVehicule = $vehicule->fetch();
$agence = $infoVehicule['agences_idagences'];
$timestamp1 = strtotime($date_heure_depart);
$timestamp2 = strtotime($date_heure_fin); // here i create two timestamps to compare with what i have en my database
$date_deja_prise = execReq( "SELECT * FROM commande WHERE vehicule_idvehicule=:idvehicule", array(
'idvehicule' => $idvehicule
));
while( $date = $date_deja_prise->fetch() ){
if( !empty($date) ){ // here if one vehicle has a date of rent it checks evry one to check if the date is taken
$date_debut = strtotime($date['date_heure_depart']);
$date_fin = strtotime($date['date_heure_fin']);
if( ($date_debut <= $timestamp1 || $timestamp2 <= $date_fin) ){
$content .= '<div class="alert alert-danger">Le véhicule '.$infoVehicule['titre'].' est déjà louer du '.$date['date_heure_depart'].' au '.$date['date_heure_fin'].' inclu</div>';
}
}
}
if( empty($content) ){
$nb_de_jour_timestamp = $timestamp2 - $timestamp1;
$nb_de_jour = $nb_de_jour_timestamp/86400;
$prix_journalier = $nb_de_jour * $infoVehicule['prix_journalier'];
execReq( "INSERT INTO commande VALUES(NULL, $idmembre, $idvehicule, $agence, :date_heure_depart, :date_heure_fin, $prix_journalier, now())", array(
'date_heure_depart' => date("Y-m-d", $timestamp1),
'date_heure_fin' => date("Y-m-d", $timestamp2)
));
$content = '<div class="alert alert-success">Votre reservation a été effectué !</div>';
}
} else {
$content .= '<div class="alert alert-danger">Pour passer une commande vous devez créer un compte <a href="" data-toggle="modal" data-target="#inscription">cliquez ici</a> pour vous en créer un</div>';
}
}
so basicaly it can create a line in my phpmyadmin page where the car is booked for some period of time and after that if i try to book an other car but all the dates are differents i can't