Joshua F Posted May 4, 2011 Share Posted May 4, 2011 I have a forum script I made that has thread bumping for the thread creator only. I am trying to limit the amout of time the creator can bump to be every 10 minutes. Here's my code. list($title, $creator, $locked, $hidden, $moved, $lastbump) = mysql_fetch_row(mysql_query('SELECT title, creator, locked, hidden, moved, lastbump FROM forum_threads WHERE id="'.$_GET['threadid'].'"')); if(($locked == 1 || $hidden == 1 || $moved == 1) && !$_SESSION['rights'] == 2){ header("location: thread.ws?id=".$_GET['threadid']."&page=".$_GET['page'].""); } else { if($creator == $_SESSION['username']){ mysql_query("UPDATE forum_threads SET lastbump = NOW() WHERE id='".$_GET['threadid']."'"); } else { header("location: thread.ws?id=".$_GET['threadid']."&page=".$_GET['page'].""); } } Quote Link to comment https://forums.phpfreaks.com/topic/235553-how-to-check-if-10-minutes-passed-since-last-bump/ Share on other sites More sharing options...
requinix Posted May 4, 2011 Share Posted May 4, 2011 Is lastbump the field that bumps the thread? I guess it also serves the "date posted" purpose? "UPDATE forum_threads SET lastbump = NOW() WHERE id='".$_GET['threadid']."' AND lastbump Also: You're vulnerable to SQL injection and that's a very bad thing. After you read up on the subject, start using functions mysql_real_escape_string and intval. Quote Link to comment https://forums.phpfreaks.com/topic/235553-how-to-check-if-10-minutes-passed-since-last-bump/#findComment-1210643 Share on other sites More sharing options...
Joshua F Posted May 5, 2011 Author Share Posted May 5, 2011 Is lastbump the field that bumps the thread? I guess it also serves the "date posted" purpose? "UPDATE forum_threads SET lastbump = NOW() WHERE id='".$_GET['threadid']."' AND lastbump <= lastbump - INTERVAL 10 MINUTE" Also: You're vulnerable to SQL injection and that's a very bad thing. After you read up on the subject, start using functions mysql_real_escape_string and intval. I do my main programming first, then go over it to prevent injects. But with that, it doesn't display the error if it hasnt been ten minutes or not. Here's my new code. list($title, $creator, $locked, $hidden, $moved, $lastbump) = mysql_fetch_row(mysql_query('SELECT title, creator, locked, hidden, moved, lastbump FROM forum_threads WHERE id="'.$_GET['threadid'].'"')); if(($locked == 1 || $hidden == 1 || $moved == 1) && !$_SESSION['rights'] == 2){ header("location: thread.ws?id=".$_GET['threadid']."&page=".$_GET['page'].""); } else { if(getBumpTime($_GET['threadid']) == true){ if($creator == $_SESSION['username']){ mysql_query("UPDATE forum_threads SET lastbump = NOW() WHERE id='".$_GET['threadid']."' AND lastbump <= lastbump - INTERVAL 10 MINUTE"); $message = 'You have successfully bumped <i>'.$title.'.'; } else { header("location: thread.ws?id=".$_GET['threadid']."&page=".$_GET['page'].""); } } else { $message = 'You have reached the bump limit - you can only bump one thread every 10 minutes.'; } } And here's my getBumpTime function. function getBumpTime($id){ list($lastbump) = mysql_fetch_row(mysql_query('SELECT COUNT(id) FROM forum_threads WHERE id="'.$_GET['threadid'].'" && ((TIMESTAMPDIFF(MINUTE, `lastbump`, NOW() ) > 1 ) or `lastbump`="0000-00-00 00:00:00")')); if($lastbump == 1){ return true; } else { return false; } } I'm also having problems with ordering it by lastbump and lastpost. Quote Link to comment https://forums.phpfreaks.com/topic/235553-how-to-check-if-10-minutes-passed-since-last-bump/#findComment-1210662 Share on other sites More sharing options...
Joshua F Posted May 5, 2011 Author Share Posted May 5, 2011 Bump. Quote Link to comment https://forums.phpfreaks.com/topic/235553-how-to-check-if-10-minutes-passed-since-last-bump/#findComment-1211108 Share on other sites More sharing options...
requinix Posted May 5, 2011 Share Posted May 5, 2011 But with that, it doesn't display the error if it hasnt been ten minutes or not. And how was I supposed to know that would be an issue? It's not like you posted anything that hinted at the idea of showing an error message. Run the query. If mysql_affected_rows() == 1 then it was bumped and if it == 0 then it was not. I'm also having problems with ordering it by lastbump and lastpost. Ordering what? Quote Link to comment https://forums.phpfreaks.com/topic/235553-how-to-check-if-10-minutes-passed-since-last-bump/#findComment-1211160 Share on other sites More sharing options...
Joshua F Posted May 6, 2011 Author Share Posted May 6, 2011 But with that, it doesn't display the error if it hasnt been ten minutes or not. And how was I supposed to know that would be an issue? It's not like you posted anything that hinted at the idea of showing an error message. Run the query. If mysql_affected_rows() == 1 then it was bumped and if it == 0 then it was not. I'm also having problems with ordering it by lastbump and lastpost. Ordering what? The query it displays the threads. I can't do bumped = 1 or 0 because it orders the list by lastpost, then It needs to order it by lastbump as well. Quote Link to comment https://forums.phpfreaks.com/topic/235553-how-to-check-if-10-minutes-passed-since-last-bump/#findComment-1211265 Share on other sites More sharing options...
requinix Posted May 6, 2011 Share Posted May 6, 2011 I can't do bumped = 1 or 0 because it orders the list by lastpost, then It needs to order it by lastbump as well. So add it to the list of ORDER BY fields. Quote Link to comment https://forums.phpfreaks.com/topic/235553-how-to-check-if-10-minutes-passed-since-last-bump/#findComment-1211631 Share on other sites More sharing options...
ignace Posted May 6, 2011 Share Posted May 6, 2011 "UPDATE forum_threads SET lastbump = NOW() WHERE id='".$_GET['threadid']."' AND lastbump <= now() - INTERVAL 10 MINUTE" Should be correct, since lastbump <= lastbump - INTERVAL 10 MINUTE makes no sense as this will always be true regardless if it has been 10 minutes. Quote Link to comment https://forums.phpfreaks.com/topic/235553-how-to-check-if-10-minutes-passed-since-last-bump/#findComment-1211659 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.