dongyimeng3764 2014-04-26 18:41
浏览 24

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

This question already has an answer here:

    $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.");
    }

sorry i've looked pretty much everywhere for this and i still can't grasp it.

Basically i'm making a booking system that allows the users to cancel but not if the time they're trying to book is less than 24 hours away.

this at the moment seems to reject every single deletion saying the there is less than 24 hours left even though there isn't.

</div>
  • 写回答

1条回答 默认 最新

  • duandaishi9268 2014-04-26 18:43
    关注

    You're comparing a string date to a unix timestamp - try changing line

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

    to be

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

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?