quickstopman Posted July 9, 2007 Share Posted July 9, 2007 im working on a homemade forum for my site and im trying to make a way to stop a person from being able to post more than 10 posts in 4 minutes (or what ever is a good time frame). and if the user does this more than 3 times there account gets deleted can someone instruct me on how to do this ?? thanks Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted July 9, 2007 Share Posted July 9, 2007 i dont think you would want to delete them just notify them that they cant post for 20 mins but just use the time then add a certain amount of time and then check it with the current time Quote Link to comment Share on other sites More sharing options...
quickstopman Posted July 9, 2007 Author Share Posted July 9, 2007 so should i make a mysql row in the user database with the amount of posts?? and make another that tells if that user can post or not??? and then in the header file it checks to see the time each time it refreshes the page? Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted July 9, 2007 Share Posted July 9, 2007 um i wouldnt make either do somin like: <?php $access = "Allow"; $i = 0; $time = time(); $query = mysql_query("SELECT * FROM posts WHERE timeposted<($time-(60*4))"); while($info = mysql_fetch_array($query)) { $i++; if($i>=10) { $access = "Deny"; } } if($access="Deny") { echo("Sorry you can't post you have posted to many times."); }else{ \\go ahead } ?> Quote Link to comment Share on other sites More sharing options...
quickstopman Posted July 9, 2007 Author Share Posted July 9, 2007 so i should but that in the header file? or on the post page? Quote Link to comment Share on other sites More sharing options...
quickstopman Posted July 9, 2007 Author Share Posted July 9, 2007 i understand what you doing but i keep getting this error now Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/pokebash/public_html/getmetola/tests/gamecoders/post.php on line 13 here is the code i have: <?php ob_start(); session_start(); include("ZZcode.h"); include("header.php"); include("config.php"); if(isset($_SESSION['email'])) { $access = "Allow"; $i = 0; $time = time(); $query = mysql_query("SELECT * FROM posts WHERE time_posted<($time-(60*4) posted_by = '{$_SESSION['id']}'"); while($timeinfo = mysql_fetch_array($query)) { $i++; if($i>=10) { $access = "Deny"; } } if($access="Deny") { echo("Sorry you can't post you have posted to many times."); }else{ if($_POST['submit']) { $errors = array(); $topic = $_POST['topic']; $content = $_POST['content']; if (empty($topic) && empty($content)) { echo ' <font color="red">Please Fill in All the forms!</font><br><br> '; echo ' <form action="'. $_SERVER['PHP_SELF'] .'" method="POST"> Topic: <input name="topic" type="text"><br><br> Post Content:<br> <textarea cols="32" rows="10px" name="content"></textarea><br> <input type="submit" name="submit" value="Post Topic"> </form> '; } else { if(isset($_SESSION['email'])) { $query = "INSERT INTO post (topic, content, time_posted , reply_to, posted_by) VALUES ('$topic', '$content', '', '$topic', '{$_SESSION['id']}')"; $result = @mysql_query($query) or die(mysql_error()); echo "Thanks for posting your topic!<br> you can view your topic <a href='posts.php'>here</a><br>"; } else { echo "you can't remotly access this form!!! SUX FOR YOU HAXOR!!!!!"; } } } else { echo ' <form action="'. $_SERVER['PHP_SELF'] .'" method="POST"> Topic: <input name="topic" type="text"><br><br> Post Content:<br> <textarea cols="32" rows="10px" name="content"></textarea><br> <input type="submit" name="submit" value="Post Topic"> </form> '; } } } else { echo "You must be logged in to post a forum topic"; } ?> anyideas? i think its in the while statement Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted July 9, 2007 Share Posted July 9, 2007 fix the query: $query = mysql_query("SELECT * FROM posts WHERE time_posted<($time-(60*4) posted_by = '{$_SESSION['id']}'"); to $query = mysql_query("SELECT * FROM posts WHERE time_posted<($time-(60*4)) AND posted_by = '{$_SESSION['id']}'"); Quote Link to comment Share on other sites More sharing options...
quickstopman Posted July 9, 2007 Author Share Posted July 9, 2007 im still getting the same error i think it might be because in the while statement you never use the declared variable what do you think other than that? Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted July 9, 2007 Share Posted July 9, 2007 can i see the updated php and where you are runing this at? Quote Link to comment Share on other sites More sharing options...
quickstopman Posted July 9, 2007 Author Share Posted July 9, 2007 oh!!!!!!!!! you had the wrong table name it was post not posts thanks but now it says even if i haven't posted anything that ive posted too many Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted July 9, 2007 Share Posted July 9, 2007 can i see the code? Quote Link to comment Share on other sites More sharing options...
quickstopman Posted July 9, 2007 Author Share Posted July 9, 2007 <?php ob_start(); session_start(); include("ZZcode.h"); include("header.php"); include("config.php"); if(isset($_SESSION['email'])) { $access = "Allow"; $i = 0; $time = time(); $query2 = mysql_query("SELECT * FROM post WHERE time_posted<($time-(60*4)) AND posted_by = '{$_SESSION['id']}'"); while($time = mysql_fetch_array($query2)) { $i++; if($i>=10) { $access = "Deny"; } } if($access="Deny") { echo("Sorry you can't post you have posted to many times."); } else if($access="Allow") { if($_POST['submit']) { $errors = array(); $topic = $_POST['topic']; $content = $_POST['content']; if (empty($topic) && empty($content)) { echo ' <font color="red">Please Fill in All the forms!</font><br><br> '; echo ' <form action="'. $_SERVER['PHP_SELF'] .'" method="POST"> Topic: <input name="topic" type="text"><br><br> Post Content:<br> <textarea cols="32" rows="10px" name="content"></textarea><br> <input type="submit" name="submit" value="Post Topic"> </form> '; } else { if(isset($_SESSION['email'])) { $query = "INSERT INTO post (topic, content, time_posted , reply_to, posted_by) VALUES ('$topic', '$content', '', '$topic', '{$_SESSION['id']}')"; $result = @mysql_query($query) or die(mysql_error()); echo "Thanks for posting your topic!<br> you can view your topic <a href='posts.php'>here</a><br>"; } else { echo "you can't remotly access this form!!! SUX FOR YOU HAXOR!!!!!"; } } } else { echo ' <form action="'. $_SERVER['PHP_SELF'] .'" method="POST"> Topic: <input name="topic" type="text"><br><br> Post Content:<br> <textarea cols="32" rows="10px" name="content"></textarea><br> <input type="submit" name="submit" value="Post Topic"> </form> '; } } } else { echo "You must be logged in to post a forum topic"; } ?> Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted July 9, 2007 Share Posted July 9, 2007 sorry if i misslead you but the query should be $query2 = mysql_query("SELECT * FROM post WHERE time_posted>($time-(60*4)) AND posted_by = '{$_SESSION['id']}'"); i might have typed it in wrong the first time but the time has to be greater than the time 4 mins ago Quote Link to comment Share on other sites More sharing options...
quickstopman Posted July 9, 2007 Author Share Posted July 9, 2007 its still not working but i also am gonna call it a night its 12:55 here night guys Quote Link to comment Share on other sites More sharing options...
quickstopman Posted July 9, 2007 Author Share Posted July 9, 2007 does anyone have a clue how to make this work? Quote Link to comment Share on other sites More sharing options...
no_one Posted July 9, 2007 Share Posted July 9, 2007 Maybe something like this? <?php $qry = mysql_query("SELECT COUNT(*) as pcount FROM post WHERE time_posted<(ADDTIME(NOW(),'00:04:00.00')) AND posted_by = '{$_SESSION['id']}'"); $qr = mysql_fetch_row($qry); if ( $qr['pcount'] > 4 ) { // deny } ?> I didn't test this, of course. Quote Link to comment Share on other sites More sharing options...
quickstopman Posted July 9, 2007 Author Share Posted July 9, 2007 i get that code cause it looks like it works but what is pcount should i add that into my users table? Quote Link to comment Share on other sites More sharing options...
no_one Posted July 9, 2007 Share Posted July 9, 2007 Nah, pcount is an alias to COUNT(*), basically just a count of how many rows (posts) were found that matched your where condition. Quote Link to comment Share on other sites More sharing options...
quickstopman Posted July 9, 2007 Author Share Posted July 9, 2007 cool Quote Link to comment Share on other sites More sharing options...
quickstopman Posted July 9, 2007 Author Share Posted July 9, 2007 now when i submit i get this error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 here is the code so far <?php ob_start(); session_start(); include("ZZcode.h"); include("header.php"); include("config.php"); if(isset($_SESSION['email'])) { $qry = mysql_query("SELECT COUNT(*) as pcount FROM post WHERE time_posted<(ADDTIME(NOW(),'00:04:00.00')) AND posted_by = '{$_SESSION['id']}'"); $qr = mysql_fetch_row($qry); if ( $qr['pcount'] > 4 ) { echo "You cannot post any more posts for the next 10 minutes, you may have been spamming!!"; } else if ($qr['pcount'] < 4) { if($_POST['submit']) { $errors = array(); $topic = $_POST['topic']; $content = $_POST['content']; if (empty($topic) && empty($content)) { echo ' <font color="red">Please Fill in All the forms!</font><br><br> '; echo ' <form action="'. $_SERVER['PHP_SELF'] .'" method="POST"> Topic: <input name="topic" type="text"><br><br> Post Content:<br> <textarea cols="32" rows="10px" name="content"></textarea><br> <input type="submit" name="submit" value="Post Topic"> </form> '; } else { if(isset($_SESSION['email'])) { $query = "INSERT INTO post (topic, content, time_posted , reply_to, posted_by) VALUES ('$topic', '$content', '', '$topic', '{$_SESSION['id']}'"; $result = @mysql_query($query) or die(mysql_error()); echo "Thanks for posting your topic!<br> you can view your topic <a href='posts.php'>here</a><br>"; } else { echo "you can't remotly access this form!!! SUX FOR YOU HAXOR!!!!!"; } } } else { echo ' <form action="'. $_SERVER['PHP_SELF'] .'" method="POST"> Topic: <input name="topic" type="text"><br><br> Post Content:<br> <textarea cols="32" rows="10px" name="content"></textarea><br> <input type="submit" name="submit" value="Post Topic"> </form> '; } } } else { echo "You must be logged in to post a forum topic"; } ?> Quote Link to comment Share on other sites More sharing options...
no_one Posted July 9, 2007 Share Posted July 9, 2007 Not sure what that's about, but another note, I used mysql_fetch_row, might want to try mysql_fetch_assoc(), and change 4 to 10.. I dunno, I'm tired, sorry Hmm, I also changed the 'time_posted' check. Checking all posted less than 4 minutes from now was wrong. Should check all posted -4 minutes from now, hah. <?php $qry = mysql_query("SELECT COUNT(*) as pcount FROM post WHERE time_posted>DATE_SUB(NOW(), INTERVAL 4 MINUTES) AND posted_by = '{$_SESSION['id']}'"); $qr = mysql_fetch_assoc($qry); if ( $qr['pcount'] > 10 ) { // deny } ?> Quote Link to comment Share on other sites More sharing options...
quickstopman Posted July 9, 2007 Author Share Posted July 9, 2007 it said that that your have an invalid argument for mysql_fetch_assoc so i changed it back to its original state and fixed the other error that was in my code not yours but now it still doesn't work Quote Link to comment Share on other sites More sharing options...
no_one Posted July 9, 2007 Share Posted July 9, 2007 okay, fetch_array or something :'( I'd think the query is fine though, for the most part. 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.