错误函数execute()on boolean,同时防止重复

时间:2017-09-18 16:55:42

标签: php mysql

我正在尝试防止从我的预订系统中复制,具有特定的房间,并且在预订的开始日期和结束日期之间,这是我开始的表格,有人帮助我约束:

Prevent date and time insert to the database

现在我正在尝试实现约束,但我在boolean()上获得错误函数execute。

约束的想法是在提交时实施,以检查在同一房间预留的表格中是否插入日期,如果保留将返回1.

这是我的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>";
    }
}
?>

0 个答案:

没有答案