ghqwerty Posted October 26, 2008 Share Posted October 26, 2008 as you might no i am setting up a limit on how many times a user can extort someone in a given time. i have added the column 'last_extortion' however whenever i try and update it to the current timestamp it wont change. could someone please show me how to update it ? whether using time() or date() Link to comment https://forums.phpfreaks.com/topic/130179-timestamp/ Share on other sites More sharing options...
dezkit Posted October 26, 2008 Share Posted October 26, 2008 http://www.tizag.com/mysqlTutorial/mysqlupdate.php Link to comment https://forums.phpfreaks.com/topic/130179-timestamp/#findComment-675087 Share on other sites More sharing options...
ghqwerty Posted October 26, 2008 Author Share Posted October 26, 2008 i know how to do that but when i do mysql_query("update members set last_extortion = ". date('Y-m-d H:i:s') ." where id = '". $_SESSION['id']."'"); then it doesnt change anything. Link to comment https://forums.phpfreaks.com/topic/130179-timestamp/#findComment-675108 Share on other sites More sharing options...
dezkit Posted October 26, 2008 Share Posted October 26, 2008 $result = mysql_query("UPDATE members SET last_extortion='".date('Y-m-d H:i:s')."' WHERE id = '". $_SESSION['id']."' ") or die(mysql_error()); Try this. Link to comment https://forums.phpfreaks.com/topic/130179-timestamp/#findComment-675112 Share on other sites More sharing options...
ghqwerty Posted October 26, 2008 Author Share Posted October 26, 2008 thanks Link to comment https://forums.phpfreaks.com/topic/130179-timestamp/#findComment-675114 Share on other sites More sharing options...
ghqwerty Posted October 26, 2008 Author Share Posted October 26, 2008 i have another problem now when drawing on that information in the table how to i put it in date() format ? so i could do if((date('y-m-d H:I:S') - $last_time) > $seconds_gap) if yes then do extortion if no then show an error message like - "You can only extort once every x minutes. You have to wait y more minutes/seconds" Link to comment https://forums.phpfreaks.com/topic/130179-timestamp/#findComment-675127 Share on other sites More sharing options...
ghqwerty Posted October 27, 2008 Author Share Posted October 27, 2008 does anyone know ? Link to comment https://forums.phpfreaks.com/topic/130179-timestamp/#findComment-675445 Share on other sites More sharing options...
Fruct0se Posted October 27, 2008 Share Posted October 27, 2008 If you pull $last_time from the DB in the format date('y-m-d H:I:S') then this will work for you. $last_time = strtotime($last_time); if((time() - $last_time) > $seconds_gap) Link to comment https://forums.phpfreaks.com/topic/130179-timestamp/#findComment-675446 Share on other sites More sharing options...
ghqwerty Posted October 27, 2008 Author Share Posted October 27, 2008 now that the servers are back up i now have a 3rd problem lol im getting this error whenever i 'extort' someone Warning: strtotime() expects parameter 1 to be string, resource given in /home/a2350935/public_html/extortion.php on line 95 this is how im using it $last_time = mysql_query("select last_extortion from members where id = '".$_SESSION['id']."'") or die(mysql_error()); $last_time = strtotime($last_time); $length = 10; $seconds_gap = $length * 60; Link to comment https://forums.phpfreaks.com/topic/130179-timestamp/#findComment-675500 Share on other sites More sharing options...
ghqwerty Posted October 27, 2008 Author Share Posted October 27, 2008 changed to $last_time = mysql_query("select last_extortion from members where id = '".$_SESSION['id']."'") or die(mysql_error()); $last_time1 = mysql_fetch_array($last_time); $last_time2 = $last_time1['last_extortion']; $last_time = strtotime($last_time2); $length = 10; $seconds_gap = $length * 60; if((time() - $last_time) > $seconds_gap){ but now whenever i try and extort someone i get 'You can only extort once every 10 minutes. You have to wait 1225107713 seconds.' Link to comment https://forums.phpfreaks.com/topic/130179-timestamp/#findComment-675507 Share on other sites More sharing options...
sammeh Posted October 27, 2008 Share Posted October 27, 2008 I would get rid of the date() and use mktime() it's a lot better for time comparison! Link to comment https://forums.phpfreaks.com/topic/130179-timestamp/#findComment-675522 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.