Jump to content

[SOLVED] simple time() + ? problem


Goose87

Recommended Posts

Hi guys,

I know this is a really simple problem, but PLEASE don't reply saying refer to the manual.  I'm pretty sure I've got my script almost working, but I'm clearly doing something wrong, so can you quickly look at it and help me out so I can learn.  I won't be a noobie forever :)

 

This is a code snippet:

$result1=@mysql_query("SELECT validated_timer FROM users WHERE user_id='$user_id'");
if($validated_timer > time()) {
$_SESSION['validated'] = 0;
echo "<meta http-equiv=\"refresh\" content=\"0;URL=mining.php\">";
exit();
} else {

 

The session works fine, and that updates.  But the timer isn't working for some reason.  I set the "validated_timer" value on the previous page when they type in the right number with this:

 

$validated_timer=time()+300;
	$result=@mysql_query("UPDATE a_users SET validated_timer='$validated_timer'");
	$_SESSION['validated'] = 1;	 //initialized session instead of the variable
	echo "<meta http-equiv=\"refresh\" content=\"0;URL=vmining.php\">";
		exit();

 

Any help would be greatly appreciated.  I know it's a simple error, but it's just not working, and it's very frustrating because i thought i'd got the right stuff.

 

Oh, and the field in the db is "timestamp".

 

Cheers, Goose.

Link to comment
Share on other sites

Ah yes, in that part I had forgotten to extract the variable, but in the later part i had put it there, yet it still doesn't work..i don't understand.

 

When i'm doing $validated_timer = time()+300;

and then inserting that value into the database it's only coming up as 0000-00-00 00:00:00 format :( why is it doing that?

Link to comment
Share on other sites

I read the thing you posted, and it said if you do an invalid input it will come out with all the 0000's which is what i'm getting..

 

but doing something like this:

 

$timer = time() + 3600;

and saving that to the database.

 

and then doing a check to see if $timer is greater than $time in the future.  I'm sure that's right, but it's just not working, i don't understand it.

 

Could someone post some example code of how they'd do it?  I need to understand it, and reading those manuals confuses me coz it goes off into all random areas that i dont need to know.

 

I just need to know what I need to do to achieve a time being saved in my database, being able to add any amount of seconds to it, and then checking if that timer is greater than the time now, to see if they are allowed to do the action.

 

Cheers guys,

I hope you can be bothered to help me on this one.  It's a simple problem and I'm not this noobed all over with php, it's just first time i've come across it and it doesnt work!  Cheers.

Link to comment
Share on other sites

time() generates the number of seconds since the start of the epoch

 

datetime is a date format (yyyy-mm-dd etc,etc).

 

They're not interchangeable.  I'd change the datetime field in the database and if you need to display a date then there are plenty of bits of date code around (even a few in the manual).

Link to comment
Share on other sites

I don't have datetime in the database, the field in the database is the timestamp field.

 

A friend who is a coder on an online game said the following to me: 

 

You use the timestamp code: time(). It's a 10 digit code, showing the number of seconds since Dec 31, 1970 00:00. You can use it to update times in the database. So, let's say someone takes a shot, and either succeeds or fails, you add a code like this:

 

$time_now = time()+300;

 

mysql_query("UPDATE users SET kill_timer = '$time_now' WHERE username = '$username'");

 

And when checking to see if the user is able to kill, you have something like this:

 

if ($kill_timer > time()) {

echo('You cannot shoot again so soon');

}

else {

...

}

 

I have basically followed that guideline, but when i try to do that sort of thing with the $kill_timer = time() + 300;  it doesn't put that figure in the database, it goes to 0000-00-00 00:00:00

 

Any idea what i'm doing wrong?

Link to comment
Share on other sites

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.