Goose87 Posted July 29, 2007 Share Posted July 29, 2007 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. Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 29, 2007 Share Posted July 29, 2007 $result1=@mysql_query("SELECT validated_timer FROM users WHERE user_id='$user_id'"); if($validated_timer > time()) { $result1 is a resource, not a variable. You need to abstract the value. Quote Link to comment Share on other sites More sharing options...
Goose87 Posted July 29, 2007 Author Share Posted July 29, 2007 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? Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 29, 2007 Share Posted July 29, 2007 I know this is a really simple problem, but PLEASE don't reply saying refer to the manual. Oh, and the field in the db is "timestamp". OK, don't refer to the manual. But if you do, remember to check this - http://dev.mysql.com/doc/refman/5.0/en/datetime.html Quote Link to comment Share on other sites More sharing options...
Goose87 Posted July 29, 2007 Author Share Posted July 29, 2007 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. Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 29, 2007 Share Posted July 29, 2007 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). Quote Link to comment Share on other sites More sharing options...
Goose87 Posted July 29, 2007 Author Share Posted July 29, 2007 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? Quote Link to comment Share on other sites More sharing options...
calabiyau Posted July 29, 2007 Share Posted July 29, 2007 try just changing that mysql field in your table to a regular integer type of an appropriate length instead of TIMESTAMP...never used that type of field before but it appears to have similar format to DATETIME. Quote Link to comment Share on other sites More sharing options...
Goose87 Posted July 29, 2007 Author Share Posted July 29, 2007 hmmm that's a good point. He never actually states that the field in the database should be a timestamp. I will fiddle and see if i can make it work, coz i'm pretty sure my coding is correct. Quote Link to comment Share on other sites More sharing options...
Goose87 Posted July 29, 2007 Author Share Posted July 29, 2007 great, thanks for the advice about changing it to an INT field calabiyau!! works perfectly now! TOTAL legend, now i can get loads more key parts of my game developed Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.