fork download
  1. <?php
  2. if (isset($_POST['submit'])) {
  3. if(!isset($connDB)){
  4. include("DBConn.php");
  5. connDB();
  6. }
  7. $checkInDate = $_POST['checkin'];
  8. $checkOutDate = $_POST['checkout'];
  9. $roomTypeId = $_POST['roomtype'];
  10. $statement = "SELECT total_room FROM room_type WHERE room_type_id = '$roomTypeId'";
  11. if ($result = mysqli_query($mysqli, $statement))
  12. {
  13. while ($row = mysqli_fetch_object($result))
  14. {
  15. $noOfRoom = $row->total_room;
  16. }
  17. }
  18. $statement = "SELECT COUNT(*) AS roomReserved FROM reservation WHERE room_type_id = '$roomTypeId' AND (begin_date <='$checkInDate' AND end_date > '$checkInDate' OR begin_date <'$checkOutDate' AND end_date >='$checkOutDate' OR begin_date >'$checkInDate' AND end_date < '$checkOutDate') ";
  19. if ($result = mysqli_query($mysqli, $statement))
  20. {
  21. while ($row = mysqli_fetch_object($result))
  22. {
  23. $roomTaken = $row->roomReserved;
  24. }
  25. }
  26. $available = $noOfRoom - $roomTaken;
  27. if ($available > 0){
  28. $_SESSION['availability'] = "The room is available. Reserve your room now";
  29. $_SESSION['checkin'] = $checkInDate;
  30. $_SESSION['checkout'] = $checkOutDate;
  31. } else {
  32. $_SESSION['availability'] = "Sorry, not available. Select a different date or a different room type";
  33. $_SESSION['checkin'] = "";
  34. $_SESSION['checkout'] = "";
  35. }
  36. header("Location: reservation.php");
  37. mysqli_close($mysqli);
  38. }
  39. ?>
  40.  
  41.  
Success #stdin #stdout 0.03s 25508KB
stdin
45
stdout