I am trying prevent duplication from my reservation system, with the specific room and in between startdate and enddate of the reservation, here is the form i started and someone helped me with the constraint:
Prevent date and time insert to the database
now am trying to implement the constraint, but i am getting error function execute on boolean().
The idea of the constraint is to be implemented on submit, to check if the inserted dates in the form reserved for the same room or no, if it's reserved will return 1.
Here is the my PHP:
<?php
session_start();
include('includes/config.php');
include('includes/checklogin.php');
check_login();
$username = $_SESSION['username'];
//code for add courses
if($_POST['submit'])
{
$officename=$_POST['officename'];
$roomname=$_POST['roomname'];
$startdate=$_POST['startdate'];
$enddate=$_POST['enddate'];
$stmt1 = $mysqli->prepare("select count(1) as counter from reservations where roomname = ? and startdate = ? between resstart and resend");
$stmt1->execute();
$stmt1->bind_result($roomname,$startdate);
$stmt1->fetch();
$query="insert into reservations (officename,roomname,resstart,resend,resuser) values(?,?,?,?,?)";
$stmt = $mysqli->prepare($query);
$stmt->bind_param('sssss',$officename,$roomname,$startdate,$enddate,$username);
if($stmt->execute() && $stmt1 == 0){
echo"<script>alert('Your Reservation Has Been Added Successfully');</script>";
}else{
echo"<script>alert('Warning! You cannot Reserve this appointment');</script>";
}
}
?>