title: Stop inserting if user clicks on the active button
body: <p>I have two buttons(Login and logout). When logout is active, if user clicks again on the logout button then shouldn't do insertion or updation. The same for login button also.</p>
  
  <p>Now, it's inserting when user clicks on the active button. I need to avoid that.</p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>&lt;script&gt;
  function insertDateTime(obj, id)
  {
  $("[id^='"+obj.id+"']").css('background', '#FFFFFF').css('font-weight', 'normal').css('font-size', '14px').css('color', 'grey');
  $(obj).css('background', '#D4B357').css('font-weight', 'bold').css('font-size', '15px').css('color', 'black');
  
  if (window.XMLHttpRequest) {
      xmlhttp=new XMLHttpRequest();
  } else { // code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  
  var params = "id="+id;
  
  xmlhttp.open("POST","insertdate.php",true);
  
  xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  /*    xmlhttp.setRequestHeader("Content-length", params.length);
  xmlhttp.setRequestHeader("Connection", "close");*/
  xmlhttp.onreadystatechange=function() {
      if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) {
          //alert(xmlhttp.responseText);
      }
  }        
  xmlhttp.send(params);
  }
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>getuser.php</strong></p>
  
  <pre><code>&lt;table&gt;
  &lt;tr&gt;
     &lt;td&gt;
         &lt;button id="btnSave" &lt;?php if($entry=='1'){?&gt; style=" background:#D4B357; font-weight:bold; font-size:15px; color:black;outline:0px;"&lt;?php }?&gt; onclick="insertDateTime(this,'&lt;?php echo $q;?&gt;');"&gt; Login&lt;/button&gt;
     &lt;/td&gt;
     &lt;td&gt;
         &lt;button id="btnSave" &lt;?php if($entry=='0'){?&gt; style=" background:#D4B357; font-weight:bold; font-size:15px;color:black;outline:0px;"&lt;?php }?&gt; onclick="insertDateTime(this,'&lt;?php echo $q;?&gt;');"&gt; Logout&lt;/button&gt;
     &lt;/td&gt;
   &lt;/tr&gt;
   &lt;/table&gt;
  </code></pre>
  
  <p><strong>insertdate.php</strong>
      date_default_timezone_set("Asia/Kolkata");
      $date=date("Y-m-d", time());?><br></p>
  
  <pre><code>&lt;?php $time=date("H:i:s",time());
  include_once "database.php";
  $q = $_POST['id'];
  
  $sql_check="select * from entries where user_id='$q' order by id desc";/*last row*/
  $res_check=mysql_query($sql_check);
  $row=mysql_fetch_array($res_check);
  $logout_date=$row['logout_date'];
  $num=mysql_num_rows($res_check);
  $id=$row['id'];
  
  if($logout_date != "" || $num=='0'){
  $sql1="insert into entries(user_id,login_date,login_time,logout_date,logout_time)values('$q','$date','$time','','')";
  $res1=mysql_query($sql1);
  $sql="update users set entry='1' where id='$q'";
  $res=mysql_query($sql);
  }
  else{
  $sql="update entries set logout_date='$date', logout_time='$time' where id='$id'";
  $res=mysql_query($sql);
  $sql1="update users set entry='0' where id='$q'";
  $res1=mysql_query($sql1);
  }
  </code></pre>