Jump to content

Recommended Posts


When a form is submitted it updates the users table field ("expired") with 

$expired = date('Y-m-d H:i:s', strtotime('+ 3 minutes'));

 

Later, if the form is resubmitted it checks the "expired" date/time and compares it to the current date/time. If the information means that the user's expired field is older than the date then the user can reuse the form, else he cannot.

Here is a block of code from which i'm having problems... it just keeps on saying "spot on" even when i modify the dates to b before..

        $stmt = $pdo->prepare("SELECT expired FROM `users` WHERE user_id = ?");
        $stmt->execute([$_SESSION['userID']]); 
        $expire_check = $stmt->fetch();

        echo $date =  date('Y-m-d H:i:s');
        echo "<br>";
        echo $expire_check['expired'];
        if ($expire_check['expired']>= date('Y-m-d H:i:s')){
            echo "<br>Too soon!";
            } else {
                echo "spot on";
            }

Help please. :)

Edit: So how exactly can i get it to display "too soon" or "spot on" from three minutes.  I know it has something to do with "strtotime", eg: 

Quote

$expired = date('Y-m-d H:i:s', strtotime('- 3 minutes'));

sadly my mental maths is no good.

 

.. this is what I'm trying atm ...:

        $stmt = $pdo->prepare("SELECT expired FROM `users` WHERE user_id = ?");
        $stmt->execute([$_SESSION['userID']]); 
        $expire_check = $stmt->fetch();

        echo $date =  date('Y-m-d H:i:s');
        echo "<br>";
        echo $expire_check['expired'];
        $date1 = date($expire_check['expired'], strtotime('+ 3 minutes'));

        if ($date1> date('Y-m-d H:i:s')){
            echo "<br>Too soon!";
            } else {
                echo "spot on";
            }

Edit:

Basically i need to save the expired date as the current date/time, and in the code add three minutes to this, then compare the +3 minute date to the current date time to decide weather it should be "too soon" or "spot on".. Help plz. :)

Edited by oz11
Link to comment
https://forums.phpfreaks.com/topic/315498-check-datetime-to-print-expire-or-not/
Share on other sites

Even though I was puzzled before, i think i found a solution..

       $stmt = $pdo->prepare("SELECT expired FROM `users` WHERE user_id = ?");
        $stmt->execute([$_SESSION['userID']]); 
        $expire_check = $stmt->fetch();

        echo $date =  date('Y-m-d H:i:s');
        echo "<br>";
        ///echo $expire_check['expired'];
        //        echo "<br>";
        //echo $date1 = date($expire_check['expired'], strtotime('+ 3 minutes'));

        echo $newDate = date('Y-m-d H:i:s', strtotime($expire_check['expired']. ' +3 minutes'));



        if ($newDate > $date){
            echo "<br>Too soon!";
            } else {
                //echo "<br>spot on";
            }

thanks. :wub: 

Unless I'm misunderstanding, right now what you have is, you take the current time and add 3 minutes to know when the form expires, and then later you take that time and add another 3 minutes to it?

This:

echo $date =  date('Y-m-d H:i:s');
echo "<br>";
echo $expire_check['expired'];

What was it outputting? Are the two values what you expected them to be?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.