mysql quick problem advice appreciated....\

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!

Moderator: General Moderators

Post Reply
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

mysql quick problem advice appreciated....\

Post 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;
}
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: mysql quick problem advice appreciated....\

Post 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)?
Last edited by requinix on Sun Sep 13, 2009 5:43 pm, edited 1 time in total.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: mysql quick problem advice appreciated....\

Post 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()
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: mysql quick problem advice appreciated....\

Post 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.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: mysql quick problem advice appreciated....\

Post 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.
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: mysql quick problem advice appreciated....\

Post 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);
}
}
 
?>
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: mysql quick problem advice appreciated....\

Post by Darhazer »

Code: Select all

if ($count=>1){
This is not valid synatx at all, the correct way is:

Code: Select all

if ($count>=1){
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
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: mysql quick problem advice appreciated....\

Post 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?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: mysql quick problem advice appreciated....\

Post by Eran »

What is the size of that table
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: mysql quick problem advice appreciated....\

Post 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.
Post Reply