0

I'm creating a booking calendar and am having issues making the timeslots that have been booked unavailable. I have populated them separately unfortunately, so the date and timeslot have no connection.

How do I check if both the timeslot and date (in the same ID) have been booked?

$name = $_POST['name']; 
$email = $_POST['email']; 
$timeslot = $_POST['timeslot']; 
$date = $_POST['date']; 

$conn = new mysqli("localhost","root","root","bookingCalendar");
if($conn->connect_error){
    die("Failed to connect : ".$conn->connect_error);
    } else {
        
    $stmt = $conn->prepare("insert into bookings(name, email, timeslot, date) values(?, ?, ?, ?)");

    $stmt->bind_param("ssss", $name, $email, $timeslot, $date); //Saves values as strings, thus further functions can't be created
    $stmt->execute();
    echo '<script>alert("Booking successful!")</script>'; 
    echo "<script> location.href='bookCal.php'; </script>";
    $stmt->close();
    $conn->close();
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
Frida
  • 1
  • 1
  • 1
    mysqli is not a database. – Dharman Jan 05 '21 at 17:46
  • Make a composite UNIQUE key in the database. – Dharman Jan 05 '21 at 17:47
  • You need to stop manually checking for errors. Please read: [Should we ever check for mysqli_connect() errors manually?](https://stackoverflow.com/q/58808332/1839439) and [Should I manually check for errors when calling “mysqli_stmt_prepare”?](https://stackoverflow.com/q/62216426/1839439) – Dharman Jan 05 '21 at 17:47
  • How are `timeslots` defined? – Steven Jan 05 '21 at 17:56

0 Answers0