1

Basically what this does is makes it so after the user presses a button, they have to wait 2 minutes to press it again. When you press it the first time, it works, then if you press it again before 2 minutes, it says "please wait 2 minutes." but after 2 minutes, you can press it as many times as you like without the error, not what I want. Here is the code

<?php
if('sub') {

$client = $_SERVER['REMOTE_ADDR'];
$username="user";
$password="pass";
$database="db";
mysql_connect(localhost,$username,$password);
$time = strtotime("2 minutes");
$now = strtotime("now");
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT Time FROM log WHERE IP='$client'";
$result= mysql_query($query);
$num=mysql_num_rows($result);


while($rows=mysql_fetch_array($result)){
$timestamp = $rows['Time'];
}
echo n; 
echo $now;
echo t;
echo $timestamp;


if($now < $timestamp)
{
echo "<center><h2 style=\"color:red\" class=\"texts\" id=\"homeLink\">Please wait 2 minutes.</h2></center>";

}
else{
//some other code

$query1 = "INSERT INTO log VALUES ('$client','$time','$username')";
$query2 = "UPDATE `log` SET `Time`='$time' SET `Username`='$username' WHERE `IP`='$client'";

if($num == 0)
{
mysql_query($query1);
}
else
{
mysql_query($query2);
}

mysql_close();
}
?>

As you can see, if there is no row for the IP of the user, it makes a new one, if there is it will update it. After the first time, it no longer works. Hope someone can help. Thanks!

1
  • You can add <?php ini_set('error_reporting', E_ALL); ?> at the very beginning of your .php script to display all errors. Try that, please. Commented Aug 11, 2012 at 13:57

2 Answers 2

1

Your update statement is a bit off, so the update fails;

UPDATE `log` SET `Time`='$time' SET `Username`='$username' WHERE `IP`='$client'"

You should only use SET once, like this;

UPDATE `log` SET `Time`='$time', `Username`='$username' WHERE `IP`='$client'"
Sign up to request clarification or add additional context in comments.

Comments

0

I'm pretty sure your database does not contain entries you think it contains. Can you check it (IPs and stuff on after button press)?

2 Comments

Yes it does contain the entries, I have checked. Im going to try to change the update statement.
But if there is only one timestamp, why are you fetching array from database?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.