0
    $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.

MISJHA
  • 998
  • 4
  • 12
  • I've asked there, but my question has changed as i fixed that issue. The thingis nobody is actually replying on there anymore. – user3381055 Apr 26 '14 at 18:43
  • 1
    You are comparing a date string to a unix time stamp, you will need to convert $date to unix time stamp too. – MISJHA Apr 26 '14 at 18:44
  • Is `$info['date']` and `$info['time']` coming from database? If so there is much easier way to get it on the way you want at the SQL query. **POST your query to get the booking!** – Prix Apr 26 '14 at 18:58
  • Also at least in the example you don't have $BookID defined. – MISJHA Apr 26 '14 at 18:59

1 Answers1

1

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

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

to be

if (strtotime($date) >= (time() + 86400)) {
Joe Pietroni
  • 826
  • 5
  • 6