PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hey guys I have a script where a post is submitted and processed in this script where there is an excerpt below. I just want to limit the submission to once every 15 seconds however obviously this script does not work. Can I use a 'greater than' symbol in a mysql statement and does anyone know how to accomplish this?
$time=time();
$timeout=$time-15;
$time_check="SELECT * FROM table WHERE time>$timeout AND t ='$td'";
$time_result=mysql_query($time_check) or die('Error, check query failed');
$count = mysql_num_rows($time_result);
if ($count>1){
echo ' <script>
alert("You can only submit every 15 seconds");
</script>';
return;
}
$query= "INSERT into b VALUES ('$time', '$td')";
$query1=mysql_query($query);
$td is defined correctly. For some reason, the entries are just inserted regardless, that's why I thought maybe you cannot use the greater than sign or less than sign in a query.
<?php
include("includes/connection.php");
if (isset($_POST['t']))
{
$td=$_POST['t'];
$time=time();
//seconds
$timeout=$time-15;
$time_check="SELECT * FROM submit WHERE time>$timeout AND t ='$td'";
$time_result=mysql_query($time_check) or die('Error, check query failed');
$count = mysql_num_rows($time_result);
if ($count=>1){
echo ' <script>
alert("You can only submit every 15 seconds");
</script>';
return;
}
else{
$query= "INSERT into submit VALUES ('$time', '$td')";
$query1=mysql_query($query);
}
}
?>
And I just noticed that in the previous code (the one posted in the first post) you check only for > 1, which means that is user have 1 post it's allowed to post.
So changing the condition in the if should resolve the issue
Thanks a lot man, it seems to be working now however when I try to submit twice within 15 seconds nothing happens when it should the second time but I do not get an error message. Could this be because the processing of the form is on another page?
it is 2 columns, time and t. I think I worded the last message wrong though. I am getting the desired effect with managing the data ie. the data can only be submitted every 15 seconds however I just do not get the error message when the data does not submit. I am accomplishing the same message effect with another error processing form so I am unsure of the problem.