title: Displaying the proper time in a counter timer everytime the page refreshes
body: <p>Well!I don't know If I made the title proper even..I'm making an online examination system..
  I'm stuck in a page right now..
  I'm having a page where I'm displaying the questions one by one i.e on click of the buttons next and previous,the respective question is displayed from the database.Above the questions,I have a timer counter which shows the remaining time for the exam.
  When I go to the exam page,all works fine.1st question gets displayed and the counter starts.
  The problem starts when I hit the next button(next &amp; prev are submit buttons) for the next question,the page gets refreshed as the next ques gets displayed 'n the counter starts from the beginning again.Here is the code for displaying the questions along with the counter made in JS....</p>
  
  <pre><code>&lt;?php
  
  require_once('connect.php');
  session_start();
  if(!isset($_SESSION['ta'])){
  $_SESSION['ta']=0;
  }
  if(!isset($_SESSION['qno'])){
  $_SESSION['qno']=1;
  $q2=$_SESSION['qno'];
  
  }
  else{
  
  if(isset($_POST['next'])){
  
      $q2=$_POST['q2'];
      $ans=$_POST['ans'];
      $_SESSION['qno']+=1;
      $reply=$_POST['question1'];
      if(isset($_POST['question1'])){
  
      $query="select `qno` from `answer` where `uname`='{$_SESSION['user']}'
   and `qno`='$q2'";
      $q_r=mysqli_query($con,$query);
  
      $n1=mysqli_num_rows($q_r);
  
      if($n1&lt;1){
  
          $_SESSION['ta']+=1;
  
      }
  
  
      $query="select `qno` from `answer` where `uname`='{$_SESSION['user
  and `qno`='$q2'";
      $q_r=mysqli_query($con,$query);
  
      $n=mysqli_num_rows($q_r);
  
      if($n&gt;0){
          $new_quer="update `answer` set `reply`='$reply' where 
  `uname`='{$_SESSION['user']}' and `qno`='$q2'";
          mysqli_query($con,$new_quer);
  
      }
      else{
          $new_q="insert into `answer`
   values('{$_SESSION['user']}',$q2,year(now()),'$ans','$reply')";
          mysqli_query($con,$new_q);
      }
  
  
  
      $reply="";
  }
  }
  
  if(isset($_POST['previous'])){
      $_SESSION['qno']-=1;
      $query="select `reply` from `answer` where 
  `uname`='{$_SESSION['user']}' and `qno`='{$_SESSION['qno']}'";
      $q_r=mysqli_query($con,$query);
      while($row=mysqli_fetch_array($q_r)){
          $reply=$row['reply'];   
      }
  }
  
  
  if(isset($_POST['exam_submit'])){
  
          $q2=$_POST['q2'];
          $ans=$_POST['ans'];
          $reply=$_POST['question1'];
          $query="select `qno` from `answer` where 
  `uname`='{$_SESSION['user']}' and `qno`='$q2'";
          $q_r=mysqli_query($con,$query);
  
          $n=mysqli_num_rows($q_r);
  
          if($n&gt;0){
              $new_quer="update `answer` set `reply`='$reply' where 
  `uname`='{$_SESSION['user']}' and `qno`='$q2'";
              mysqli_query($con,$new_quer);
          }
          else{
              $all_quer="insert into `answer` 
              values('{$_SESSION['user']}',
  {$_SESSION['qno']},year(now()),'$ans','$reply')";
              mysqli_query($con,$all_quer);
  
          }
          $new_q="insert into `answer` 
  values('{$_SESSION['user']}',$q2,year(now()),'$ans','$reply')";
          mysqli_query($con,$new_q);
          header('Location:result.php');      
  }
  } 
  
  $q="select * from `uquestion` where `qno`='{$_SESSION['qno']}' and 
  `uname`='{$_SESSION['user']}'";
  $result=mysqli_query($con,$q);
  
  if ($result) {
  
  while($row=mysqli_fetch_array($result)){
  
  $qno = $row['qno'];
  $question = $row['question'];
  $op1 = $row['op1'];
  $op2 = $row['op2'];
  $op3 = $row['op3'];
  $op4 = $row['op4'];
  $answer = $row['answer'];
  
  }
  }
  
  ?&gt;
  
  &lt;div id="counter"&gt;
  &lt;form name="counter" style="text-align:center;" action="result.php"
  method="post"&gt;
  &lt;input type="text" name="hh" id="hh" size="5" style="margin-top:5px; 
  height:25px; text-align:center; font-size:18px; 
  font-weight:bold; font-family:Verdana; color:blue; text-align:center;"&gt; 
  &lt;input type="text" name="mm" id="mm" size="5" style="margin-top:5px;
  height:25px; text-align:center; font-size:18px; 
  font-weight:bold; font-family:Verdana; color:green; text-align:center;"&gt; 
  &lt;input type="text" name="ss" id="ss" size="5" style="margin-top:5px;
  height:25px; text-align:center; font-size:18px; 
  font-weight:bold; font-family:Verdana; color:red; text-align:center;"&gt;
  &lt;br&gt;   &lt;/form&gt; &lt;/div&gt;
  &lt;span style="margin-left: 39.7%; font-family:Verdana; font-weight:bold;
  font-size:17px; color:blue"&gt;  
  Hour &lt;/span&gt; 
  &lt;span style="margin-left: 3.3%; font-family:Verdana; font-weight:bold; 
  font-size:17px; color:green;"&gt;  
  Minute &lt;/span&gt;
  &lt;span style="margin-left:2.1%; text-align:center; font-family:Verdana;
  font-weight:bold; font-size:17px; color:red;"&gt;  
  Second &lt;/span&gt;
  
  &lt;div style="margin-top:13px; background:-moz-linear-
  gradient(top,white,#FCF,#E6E6E6,#FFF8DC); 
  width:50%; margin-left:22%; padding-top:11px; padding-bottom:12px; 
  padding-left:2%;"&gt;
  
  &lt;form name="exam" method="post" action="exam.php"&gt;
  &lt;input type="hidden" name="ans" value="&lt;?php echo $answer; ?&gt;"&gt;
  &lt;input type="hidden" name="q2" value="&lt;?php echo $_SESSION['qno']; ?&gt;"&gt;
   &lt;table width="100%" cellpadding="5"&gt;
  &lt;tr&gt; &lt;td style="border-bottom:2px solid blue; font-size:15px; color:blue; 
  font-weight:bold;
  text-shadow:rgba(160,160,200,0.5) 5px 6px 4px; font-family:Verdana;"&gt;
  Question : &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td style="font-size:16px; color:red; font-weight:bold; 
  text-shadow:rgba(200,160,170,0.6) 6px 7px 4px;
  font-family:verdana;"&gt; 
  &lt;?php echo $question ?&gt; &lt;/td&gt; &lt;/tr&gt;
  
  &lt;tr&gt; &lt;td style="text-shadow:rgba(160,200,270,0.5) 5px 6px 4px; 
  font-size:14px; color:green; font-weight:bold;
  font-family:verdana;"&gt;
  
  &lt;input type="radio" name="question1" id="q1" value="op1" &lt;?php    
  if($reply=="op1"){ echo 'checked="checked"';}
  
   ?&gt; /&gt;
  &lt;?php echo $op1; ?&gt;&lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td style="text-shadow:rgba(160,200,270,0.5) 5px 6px 4px; 
  font-size:14px; color:green; font-weight:bold;
  font-family:verdana;"&gt;
  &lt;input type="radio" name="question1" id="q2" value="op2" &lt;?php 
  if($reply=="op2"){ echo 'checked="checked"';}?&gt; /&gt; 
  &lt;?php echo $op2;  ?&gt; &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td style="text-shadow:rgba(160,200,170,0.5) 5px 6px 4px; 
  font-size:14px; color:green; font-weight:bold;
  font-family:verdana;"&gt;
  &lt;input type="radio" name="question1" id="q3" value="op3" &lt;?php 
  if($reply=="op3"){ echo 'checked="checked"';}?&gt; /&gt; 
  &lt;?php echo $op3;  ?&gt; &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td style="text-shadow:rgba(160,200,170,0.5) 5px 6px 4px; 
  font-size:14px; color:green; font-weight:bold;
  font-family:verdana;"&gt;
  &lt;input type="radio" name="question1" id="q4" value="op4" &lt;?php 
  if($reply=="op4"){ echo 'checked="checked"';}?&gt; /&gt; 
  &lt;?php echo $op4;  ?&gt; &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td&gt;
  &lt;input type="submit" name="previous" value="Previous" style="width:16%; 
   height:30px;" &lt;?php if($qno==1)
   echo 'disabled="disabled"'?&gt;&gt;
   &lt;input type="submit" name="next" value="Next" style="width:16%; 
  height:30px;" &lt;?php if($qno==5)
  echo 'disabled="disabled"'?&gt;&gt;  &lt;/td&gt; &lt;/tr&gt;
  
  &lt;tr&gt; &lt;td style="text-shadow:rgba(160,160,200,0.5) 4px 5px 4px; 
  font-size:12px; color:#03F; font-weight:bold;
  font-family:verdana; border-top:2px solid blue;"&gt; Question &lt;?php 
  echo $qno; ?&gt; of 10 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td style="text-shadow:rgba(160,160,200,0.5) 4px 5px 4px;
  font-size:12px; color:#03F; font-weight:bold;
  font-family:verdana;"&gt; Total Attempted : &lt;?php echo $_SESSION['ta']; ?&gt; 
  &lt;/td&gt; &lt;/tr&gt;
  
  &lt;tr&gt; &lt;td&gt;
  &lt;input type="submit" name="exam_submit" value="I'm done!Submit Test"
  onclick="return confirm('Are you Sure?')"
  style="width:97%; height:37px; background:green;
  color:white; font-family:Verdana; font-size:15px; font-weight:bold;"&gt;
    &lt;/td&gt; &lt;/tr&gt; 
   &lt;/table&gt;
  &lt;/form&gt;
  
  &lt;script language="javascript"&gt;
  
  var sec=0; 
  var mins=1; 
  document.counter.hh.value=00;
  document.counter.mm.value=mins;
  document.counter.ss.value=sec;
  function display(){
  if(document.counter.mm.value=="00" &amp;&amp;  document.counter.ss.value=="00"){
      document.counter.submit();
  }
  
  if (sec&lt;=0){ 
  sec=60 
  mins-=1 
  } 
  if (mins&lt;=-1){ 
  sec=0 
  mins+=1 
  } 
  else 
  sec-=1
  
  if(sec&lt;10){
  sec=sec*1;
  sec='0'+sec;
  }
  if(mins&lt;10){
  mins=mins*1;
  mins='0'+mins;
  }
  
  document.counter.mm.value=mins;
  document.counter.ss.value=sec;
  
  setTimeout("display()",1000)
  
  }
  
  display();
  
  &lt;/script&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Please suggest how to deal with it.Your help is really really appreciated.</p>