Page 1 of 1
mysql quick problem advice appreciated....\
Posted: Sun Sep 13, 2009 4:34 pm
by scarface222
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?
Code: Select all
$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;
}
Re: mysql quick problem advice appreciated....\
Posted: Sun Sep 13, 2009 4:39 pm
by requinix
Looks fine to me, assuming $td is defined correctly. Are you sure you aren't using time()-15 in your INSERT statement(s)?
Re: mysql quick problem advice appreciated....\
Posted: Sun Sep 13, 2009 4:47 pm
by Darhazer
tasairis wrote:Looks fine to me, assuming $td is defined correctly. Are you sure you use time()-15 in your INSERT statement(s)?
Actually in the insert it should be just time()
Re: mysql quick problem advice appreciated....\
Posted: Sun Sep 13, 2009 5:16 pm
by scarface222
this is the insert statement
Code: Select all
$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.
Re: mysql quick problem advice appreciated....\
Posted: Sun Sep 13, 2009 5:55 pm
by Darhazer
You can use >
But maybe you are running the insert code regardless the check? If you post the whole code, it will be easier to find the problem.
Re: mysql quick problem advice appreciated....\
Posted: Sun Sep 13, 2009 6:32 pm
by scarface222
Of course, sorry man.
Code: Select all
<?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);
}
}
?>
Re: mysql quick problem advice appreciated....\
Posted: Sun Sep 13, 2009 6:36 pm
by Darhazer
This is not valid synatx at all, the correct way is:
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
Re: mysql quick problem advice appreciated....\
Posted: Sun Sep 13, 2009 6:44 pm
by scarface222
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?
Re: mysql quick problem advice appreciated....\
Posted: Sun Sep 13, 2009 7:31 pm
by Eran
What is the size of that table
Re: mysql quick problem advice appreciated....\
Posted: Sun Sep 13, 2009 7:53 pm
by scarface222
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.