Bonjour à tous, j’ai avancé dans mon projet mais j’ai des messages d’erreurs.
Remarque: Variable indéfinie: numéro_chambre dans C: \ wamp64 \ www \ hotels_clients \ process \ process_booking.php sur la ligne 38
Erreur fatale: exception PDO non détectée: SQLSTATE [42S22]: colonne non trouvée: 1054 Champ '$ Arrivaldate_form' inconnu dans on clause dans C: \ wamp64 \ www \ hotels_clients \ class \ bookingManager.php sur la ligne 68
PDOException: SQLSTATE [42S22]: Colonne introuvable: 1054 Champ '$ Arrivaldate_form' inconnu dans on clause dans C: \ wamp64 \ www \ hotels_clients \ class \ bookingManager.php sur la ligne 68
MariaDB [hotels]> DESCRIBE booking;
+
| Field | Type | Null | Key | Default | Extra |
+
| id | int(11) | NO | PRI | NULL | auto_increment |
| room_number | varchar(255) | NO | | NULL | |
| customer_id | int(11) | NO | | NULL | |
| customer_name | varchar(255) | NO | | NULL | |
| hotel_name | varchar(255) | NO | | NULL | |
| booking_date | date | NO | | NULL | |
| arrival_date | date | NO | | NULL | |
| departure_date | date | NO | | NULL | |
+
8 rows in set (0.027 sec)
MariaDB [hotels]> DESCRIBE customer;
+
| Field | Type | Null | Key | Default | Extra |
+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | | NULL | |
| email | varchar(255) | NO | | NULL | |
+
3 rows in set (0.025 sec)
MariaDB [hotels]> DESCRIBE hotel;
+
| Field | Type | Null | Key | Default | Extra |
+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | | NULL | |
| address | varchar(255) | NO | | NULL | |
| postal_code | varchar(5) | NO | | NULL | |
| city | varchar(255) | NO | | NULL | |
| phone | varchar(14) | NO | | NULL | |
+
6 rows in set (0.025 sec)
MariaDB [hotels]> DESCRIBE room;
+
| Field | Type | Null | Key | Default | Extra |
+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | | NULL | |
+
2 rows in set (0.029 sec)
MariaDB [hotels]> NOTEE;
class bookingManager {
private $_db;
public function __construct(PDO $db) {
$this->setDb($db);
}
public function setDb($dbh) {
$this->_db = $dbh;
}
public function addBooking(Booking $booking) {
$sql = 'INSERT INTO booking (room_number, customer_id, customer_name, hotel_name, booking_date, arrival_date, departure_date)
VALUES(:room_number, :customer_id, :customer_name, :hotel_name, :booking_date, :arrival_date, :departure_date)';
$room_number = htmlspecialchars($booking->getRoomNumber());
$customer_id = $booking->getCustomerId();
$customer_name = htmlspecialchars($booking->getCustomerName());
$hotel_name = htmlspecialchars($booking->getHotelName());
$booking_date = $booking->getBookingDate();
$arrival_date = $booking->getArrivalDate();
$departure_date = $booking->getDepartureDate();
$stmnt = $this->_db->prepare($sql);
$stmnt->bindParam(':room_number', $room_number);
$stmnt->bindParam(':customer_id', $customer_id);
$stmnt->bindParam(':customer_name', $customer_name);
$stmnt->bindParam(':hotel_name', $hotel_name);
$stmnt->bindParam(':booking_date', $booking_date);
$stmnt->bindParam(':arrival_date', $arrival_date);
$stmnt->bindParam(':departure_date', $departure_date);
if($stmnt->execute()) {
return true;
}
else {
return false;
}
}
public function getRoom($room_number) {
$sql = 'SELECT RO.id FROM room AS RO
LEFT JOIN booking AS BO
ON (RO.id = BO.room_number
AND ($arrivaldate_form BETWEEN BO.arrival_date AND BO.departure_date
OR $departuredate_form BETWEEN BO.arrival_date AND BO.departure_date
OR BO.arrival_date BETWEEN $arrivaldate_form AND $departuredate_form
OR BO.departure_date BETWEEN $arrivaldate_form AND $departuredate_form))
WHERE BO.room_number IS NULL
';
$stmnt = $this->_db->prepare($sql);
$stmnt->bindParam(':room_number', $room_number);
$stmnt->execute();
$count = $stmnt->rowCount();
return $count;
}
}
require('../includes/inc_connexion.php');
require('../class/Booking.php');
require('../class/bookingManager.php');
if(isset($_POST['submit_form'])) {
if((empty($_POST['username_form'])) OR (!isset($_POST['hotelname_form']))
AND (!isset($_POST['bookingdate_form'])) AND (!isset($_POST['arrivaldate_form'])) AND (!isset($_POST['departuredate_form']))) {
$message = '<p class="error">Tous les champs doivent être remplis !</p>';
}
else {
$username_form = trim($_POST['username_form']);
$hotelname_form = trim($_POST['hotelname_form']);
$bookingdate_form = trim($_POST['bookingdate_form']);
$arrivaldate_form = trim($_POST['arrivaldate_form']);
$departuredate_form = trim($_POST['departuredate_form']);
$booking_data = array(
'id' => 1,
'customer_name' => $username_form,
'hotel_name' => $hotelname_form,
'booking_date' => $bookingdate_form,
'arrival_date' => $arrivaldate_form,
'departure_date' => $departuredate_form
);
$booking = new Breve($booking_data);
$manager = new bookingManager($db);
if(!$manager->getRoom($room_number)) {
$message = '<p class="error">Pas de chambre entre cette date</p>';
}
else {
$booking = $manager->addBooking($booking);
var_dump($booking);
}
}
}
Merci d’avance pour votre aide.