看日期是否少于24小时,然后如果声明取决于

时间:2014-04-26 18:41:20

标签: php date datetime time

    $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小时的时间。

1 个答案:

答案 0 :(得分:1)

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

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

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