title: Jquery Post not working correctly?
body: <p>I have been working on Like and Unlike feature with jquery, ajax and php. My problem is little bit difficult to understand. Lets try to understand it first.
  <hr>I have 2 php pages, <code>viewProfile.php</code> and <code>LikeMail.php</code>. <code>LikeMail.php</code> is being called by ajax function in <code>viewProfile.php</code>.
  <br><br><b>Here is Section of viewProfile.php page's description</b></p>
  
  <pre><code>                             -----------------
                              |   Like/Unlike   |
                               -----------------
  </code></pre>
  
  <p>Here is button  which actually comes from <code>LikeMail.php</code> by this ajax function</p>
  
  <pre><code>function like()
  {
      var req  = new XMLHttpRequest();
      req.onreadystatechange = function()
  
      {
          if(req.readyState==4 &amp;&amp; req.status==200)
          {
              document.getElementById('Like').innerHTML=req.responseText;
  
          }
      }
      req.open('POST','LikeMail.php','true');
      req.send();
  }
  setInterval(function(){like()},1000);
  </code></pre>
  
  <p><b>HTML:</b></p>
  
  <pre><code>&lt;div id="Like"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>Output is being shown here in this div. <i>Button above may be <code>Like</code> or <code>Unlike</code> depends on the condition in <code>LikeMail.php</code> which will be described below in <code>LikeMail.php</code> description section.</i>
  <br><br>
  When one of them (buttons) <code>Like</code> or <code>Unlike</code> is clicked. It then calls respective jquery click function which sends post request to <code>LikeMail.php</code>.I have mentioned <code>Indirect</code> page in title because <code>Like</code> or <code>Unlike</code> buttons actually exists in <code>LikeMail.php</code> page. But due to ajax call these buttons are being shown in <code>viewProfile.php</code> page. So I then send post requests through <code>viewProfile.php</code> to actual page <code>LikeMail.php</code><br><br><b>It is jquery post for <code>Unlike</code> button</b></p>
  
  <pre><code>$(document).ready(function(){
  
      $('#Unlike').unbind().click(function(){
          $.post("LikeMail.php",
              {Unlike: this.id},
              function(data){
                  $('#response').html(data);
              }
  
          );
  
      });
  
  });
  </code></pre>
  
  <p><b>It is jquery post or <code>Like</code> button</b></p>
  
  <pre><code>$(document).ready(function(){
  
      $('#Like').unbind().click(function(){
          $.post("LikeMail.php",
              {Like: this.id},
          function(data){
              $('#response').html(data);
          }
          );
  
      });
  
  });
  </code></pre>
  
  <p><br>End of description section of <code>viewProfile.php</code> page<hr>
  <br>
  <b>Here is Section of LikeMail.php page's description</b>
  <br><br><code>Like</code> or <code>Unlike</code> button is shown in <code>viewProfile.php</code> page depends upon this code:</p>
  
  <pre><code>$check_for_likes = mysqli_query($conn, "SELECT * FROM liked WHERE user1='$user1' AND user2='$user2'");
                  $numrows_likes = mysqli_num_rows($check_for_likes);
                  if (false == $numrows_likes) {
                      echo mysqli_error($conn);
                  }
  
                  if ($numrows_likes &gt;= 1) {
                      echo '&lt;input type="submit" name="Unlike" value="Unlike" id="Unlike" class="btn btn-lg btn-info edit"&gt;';
  
  
                  }
  
                  elseif ($numrows_likes == 0) {
                      echo '&lt;input type="submit" name="Like" value="Like" id="Like" class="btn btn-lg btn-info edit"&gt;';
                  }
  </code></pre>
  
  <p>Button depends upon these two above conditions.<br>
  <br>Now when <code>Like</code> button is clicked, post request from <code>viewProfile.php</code> comes here</p>
  
  <pre><code>if(isset($_POST['Like']))   //When Like button in viewProfile.php is clicked then this peace of code inside if condition should run and insert some record in database
              {
                  $total_likes = $total_likes+1;
                  $like = mysqli_query($conn, "UPDATE user SET user_Likes = '$total_likes' WHERE user_id = '$user2'");
                  $user_likes = mysqli_query($conn, "INSERT INTO liked (user1,user2) VALUES ('$user1','$user2')");
                  $query3 = "INSERT INTO notification (user1, user2, alert, notificationType) VALUE ('$user1','$user2','unchecked','like')";
                  if (mysqli_query($conn, $query3)) {
                      echo "Like";
                  } else {
                      echo mysqli_error($conn);
                  }
  
              }
  </code></pre>
  
  <p>Similarly when <code>Unlike</code> button is clicked. This peace of code should run.</p>
  
  <pre><code>if(isset($_POST['Unlike'])) //This is the condition for Unlike button. It should delete record from databse
              {
                  $total_likes = $total_likes-2;
                  $like = mysqli_query($conn, "UPDATE user SET user_Likes='$total_likes' WHERE user_id='$user2'");
                  $remove_user = mysqli_query($conn, "DELETE FROM liked WHERE user1='$user1' AND user2='$user2'");
                  $query3 = "DELETE FROM notification WHERE user1='$user1' AND user2='$user2' AND notificationType='like'";
  
                  $check = mysqli_query($conn, $query3);
                  if ($check) {
                      echo "Unlike";
                  } else {
                      echo mysqli_error($conn);
                  }
              }
  </code></pre>
  
  <p><br><b>Problem:</b><br>
  Main problem which I faced is that when I click <code>Like</code> or <code>Unlike</code> both executes the condition of <code>Like</code> button code. Both inserts the data into database as <code>Unlike</code> condition should delete data from database but it also inserts data as condition for <code>Like</code> button do. Kindly can you please help me that how to tackle this problem. Thanks in advance!
  <br><br><b>Update:</b><br>When I delete all the respective code for <code>Like</code> button. The condition for <code>Unlike</code> button starts working correctly.</p>