<?php include("conn.php");//add connection to the php page //to check for member session session_start(); // if don't have session user..then if(! isset($_SESSION['memname'])) { session_write_close(); die("<script>alert('Please login first before booking courts!');window.location.href='login.html';</script>"); } //To check whether the duration selected is compatible with the start time and end time $duration= $_POST['duration']; $date1 = $_POST['starttime']; $date2 = $_POST['endtime']; $diff = round((strtotime($date2) - strtotime($date1))/(60*60)); if ($diff != $duration) { echo "<script>alert('Please make sure that the duration selected is correct with the start time and end time!');</script>"; die("<script>window.history.go(-1);</script>"); } //To check that the booking is on future not the past $date = $_POST['starttime']; $datenow = date('Y-m-d H:i a'); if ($date < $datenow) { echo "<script>alert('Please make sure that your booking date time is valid!'); </script>"; die("<script>window.history.go(-1);</script>"); } //To prevent double booking of the court at same time $courtnumber = $_POST['cid']; $bookingstarttime = $_POST['starttime']; $bookingendtime = $_POST['endtime']; $checkBookingQuery = "SELECT * FROM `volleyball_court_booking` WHERE `Court_ID` = {$courtnumber} AND (Start_Time >= '{$bookingstarttime}' AND End_Time <= '{$bookingendtime}')"; $checkBooking = mysqli_query($conn, $checkBookingQuery); if(mysqli_num_rows($checkBooking)>0) { echo "<script>alert('Sorry the court is booked by other during that period of time! Please try with other date time/courts!'); </script>"; die("<script>window.history.go(-1);</script>"); } $bid = $_POST['bid']; $cid = $_POST['cid']; $starttime = $_POST['starttime']; $endtime = $_POST['endtime']; $duration = $_POST['duration']; $sql = "UPDATE volleyball_court_booking SET Court_ID = '$cid', Start_Time = '$starttime', End_Time = '$endtime', Duration = '$duration' WHERE Booking_ID = '$bid'"; $result = mysqli_query($conn, $sql); if($result) { echo '<script> alert("Successfully change for booking time!");</script>'; echo "<script>window.location.href='booking_history.php';</script>"; } else { echo '<script> alert("Data Not Updated!");window.history.go(-1);</script>'; } ?>