質問

I have created a button called "Generate" , when click event is performed it should start a timer after reaching 60 sec it should perform an if statement. I tried the following code but its not working.

if(isset($_POST['generate']))
      {
       $timer = time();
        if($timer = $timer+5)
       {
         $query = mysql_query("UPDATE user_login SET password='' WHERE username = 'ajai sandy'") ;
                     $qry_run = mysql_query($query);
       }

In the above code I have used the system time , I could use both the system time or a timer to complete this action.

役に立ちましたか?

解決

if(isset($_POST['generate']))
      {
      sleep(60);
      // AND NOW action;
      }

But rather use JS...

他のヒント

You shouldn't do this on server side! But you could do it with PHP's sleep() method.

Do you want, that 'if' performs after 60 seconds? Then you need to use sleep()

if(isset($_POST['generate']))
  {
   sleep(60);
   if(condition)
   {
    // todo
   }

You need to just first check the current time then after you need to use sleep

if(isset($_POST['generate']))
      {
       $timer = time();
     sleep(5)

        //your condition

or you can just use this with client side scripting lanugage as well there is a function setTimeout

window.setTimeout(FUNCTION_NAME,60);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top