time in between posts

Ok what i want to do is limit the time in between my users posting comments on profiles on my site. I understand its a bad idea to use sessions to do this as people spamming can easily avoid this and cookies are right out the window. I am going to do it using the database. I have created a column called lastposted in my users table. First questions is what data type should this be ive currently got it as datetime. I have never really handled dates in php before so please bare with me!

This is the snipet of code i have to handle the comments, it runs within my profile.php so its only part of that page.

Please read the comments in the code which will help you understand what im stuck on.

//check when user last posted.
mysql_select_db(‘shermscr_userboss’, $connection) or die (“Database not found.”);
$sql = “SELECT * FROM users WHERE username = ‘$user’”;
$result=mysql_query($sql, $connection);
$a_row = mysql_fetch_assoc($result);

        if(//IF TIME NOW IS LESS THAN DATABASE TIME THEN USER HAS NOT WAITED 10 SECONDS) {
        echo "cant post for 10 seconds. server time:".getdate()." database entry ".$a_row["posteddate"];
        $postwaiterror = 1;
        }
      
        if (($commentsSize != 1) && ($commentsEmpty != 1) && ($postwaiterror != 1)){
        mysql_select_db('shermscr_userboss', $connection) or die ("Database not found.");
        mysql_query("INSERT INTO `shermscr_userboss`.`comments` (`profile` ,`username` ,`comment` ,`posteddate`) VALUES ('$profile', '$user', '$comments', NOW( ))",$connection);
        $comments = "";
        $datePlus10 = //should be date plus 10 seconds how do i write that?
        mysql_query("UPDATE users SET lastposted = '$sqldate' WHERE username = '$user'", $connection); 
        
        }
        
        }

Have a look here, it should help :slight_smile:

http://www.webdeveloper.com/forum/showthread.php?t=236044

Sponsor our Newsletter | Privacy Policy | Terms of Service