如果日期小于24小时,则视语句而定


seeing if date is less than 24 hours, then if statement depending

    $test = $info['date'] . $info['time'];
    $date = date("Y-m-d H:i:s", strtotime($test));
    if (isset($_SESSION['id']) && $_SESSION['id'] == $_GET['id'])
    {
        if (isset($_GET['BookID']) && is_numeric($_GET['BookID']))
        {
            if ($date >= (time() + 86400)) {
            // current time is 86400 (seconds in 24 hours) or less than stored time
                $sql = "DELETE FROM `tbl_booking` WHERE `BookID`={$BookID}";
                $result = mysqli_query($con, $sql);
                //header("refresh:5;url=dashboard.php");
                echo "Your booking has been cancelled.";
            }
        }
    } else {
        // if id isn't set, or isn't valid, redirect back to view page
        //header("refresh:5;url=dashboard.php");
        echo ("Sorry, there is less than 24 hours left and you cannot cancel.");
    }

对不起,我到处找这个,但我还是抓不住。

基本上,我正在制作一个预订系统,允许用户取消预订,但如果他们试图预订的时间不到24小时,就不能取消。

目前,这似乎拒绝了每一条删除,称剩余时间不到24小时,尽管没有。

您正在将字符串日期与unix时间戳进行比较-请尝试更改行

if ($date >= (time() + 86400)) {

成为

if (strtotime($date) >= (time() + 86400)) {