Jump to content

[SOLVED] Help with if statement


thefollower

Recommended Posts

I have a problem with my script and am not sure how to get it working correctly.

 

I have it checking to see if 2 hours has passed but it doesn't seem to check it properly.

This is what i have:

 

<?php
//get date and now date comparison

$GetDate = mysql_query("SELECT TIMEDIFF(NOW(), Started) AS MinutesPassed FROM users
WHERE  UserID='{$_SESSION['Current_User']}'")
or die(mysql_error());

$row = mysql_fetch_assoc($GetDate);
$Check = strtotime($row['MinutesPassed']);
?>

Max Time Length: 02:00:00
<br>
Current Time Passed: <?php echo $row['MinutesPassed'];?>
<br>

<?php

// 1221271200 is apparently 02:00:00 in integer format

If($row['MinutesPassed'] == '02:00:00' OR $Check > 1221271200){
$UPDATE = mysql_query("UPDATE users SET StartValidate='0' WHERE UserID='{$_SESSION['Current_User']}'")
Or die(mysql_error());
?>
You have finished!
<br><br>
<?php
}
?>

 

I get you have finished straight away when i should not be.. it should be waiting 2 hours ... =/ where did i go wrong?

Link to comment
https://forums.phpfreaks.com/topic/124128-solved-help-with-if-statement/
Share on other sites

I know lol

 

How ever when i did :

 

$Var = '02:00:00';
$Var = strtotime($Var);
Echo $Var;

It gives :

1221271200

 

which is why i'm confused

 

So then i assumed if the number is higher than 1221271200 it would suggest that 2 hours has definitely passed =/.

 

Yup. Whuch means that strtotime("02:00:00") returns a timestamp for 2:00 am TODAY. That's why you got those millions of seconds.

 

If you want to check if two hours passed, just check for 7200 seconds passed. No need for strtotime for that.

Great. So let's modify your query a little.

$query = "SELECT TIME_TO_SEC(TIMEDIFF(NOW(), Started)) AS SecondsPassed FROM users WHERE  UserID='{$_SESSION['Current_User']}'";

 

 

Now you should get number of secods that passed from the date stored in 'Started'

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.