PHP, MySQL Query, not working propertly.

9 views
Skip to first unread message

Mako Edvin

unread,
Jun 12, 2014, 9:18:06 AM6/12/14
to xamp...@googlegroups.com
I'm creating a 'report post' system for my website, all worked good, until i've changed the query to check if an user pressed report multiply times, and i want to stop that.
I made a field, where i put the sum of current timestamp plus 5 days, until the user could give another report on selected post.

$result = mysql_query("SELECT * FROM `reports` WHERE (`lastrep` < $timestamp) AND (`user_id` = " . $_POST['myid'] . ") AND `post_id` = " . $_POST['post_id'] . " ORDER BY `date` DESC LIMIT 0,1") or die("Mysql verify error:" . mysql_error());
if(!mysql_num_rows($result))
{
$today = date('Y-m-d');
$timestap += 3600*24*5;
mysql_query("INSERT INTO `reports` (`user_id`,`reportedUser`,`post_id`,`title`,`ip`,`date`,`lastrep`) VALUES(" . $_POST['myid'] . ", '" . $_POST['repuser'] . "', " . $_POST['post_id'] . ", '" . $_POST['title'] . "', '" . $_SERVER['REMOTE_ADDR'] . "', '$today', $timestamp)") or die("Report Insert Error: " . mysql_error());
echo
"
success, post reported.
";
}
else
{
echo
"
error, you can report this post, once in 5 days.
";
}
mysql_free_result($result);

Ok, the problem is that $timestamp variable is greather than value in `lastrep` and i'm receiving "error, you can report this post, once in 5 days."

I know that i can chceck if user can report the post by getting the `lastrep` and check with time() but i want to do this in query if possible.
Reply all
Reply to author
Forward
0 new messages