문제

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