title: PHP Like/Unlike button with jquery
body: <p>i was following a tutorial on youtube to make a simple Like/unlike button for my status system, i got most of it done, but it will not UPDATE my likes and not INSERT the like into the database, please help me say whats wrong, i tried so much now..</p>
  
  <p><strong>Function to get status:</strong></p>
  
  <pre><code> function getStatus($conn) {
         $sql = "SELECT * FROM status ORDER BY sid DESC";
         $query = mysqli_query($conn, $sql);
         while ($row = $query-&gt;fetch_assoc()) {
             echo "&lt;div class='post'&gt;".$row['message']."&lt;br&gt;";
  
                  $result = mysqli_query($conn, "SELECT * FROM status_like WHERE uid=1 and sid=".$row['sid']."");
                  if (mysqli_num_rows($result) == 1) {
                      echo "&lt;span&gt;&lt;a href='' class='unlike' id='".$row['sid']."'&gt;unlike&lt;/a&gt;&lt;/span&gt;";
                  } else {
                      echo "&lt;span&gt;&lt;a href='' class='like' id='".$row['sid']."'&gt;like&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;";
                  }
                  }
  
  
         }
  </code></pre>
  
  <p><strong>jquery code</strong></p>
  
  <pre><code> &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"&gt;&lt;/script&gt;
            &lt;script type="text/javascript"&gt;
              $(document).ready(function(){
                  $('.like').click(function(){
                      var sid = $(this).attr('id');
                      $.ajax({
                          url: 'test.php',
                          type: 'post',
                          async: false,
                          data: {
                              'liked': 1,
                              'sid': sid
  
                          },
                          success:function(){
  
                          }
                      });
                  });
              });
            &lt;/script&gt;
  </code></pre>
  
  <p><strong>and the last php code where i think the problem is:</strong></p>
  
  <pre><code>if (isset($_POST['liked'])) {
          $sid = $_POST['sid'];
          $sql = "SELECT * FROM status WHERE sid=$sid";
          $query = mysqli_query($conn, $sql);
          $row = mysqli_fetch_array($query);
          $n = $row['likes'];
          $uid = 1;
  
          $sql2 = "UPDATE status SET likes=$n+1 WHERE sid=$sid";
          $sql3 = "INSERT INTO status_like (uid, sid, username) VALUES (1, '$sid', '$uid')";
          mysqli_query($conn, $sql2);
          mysqli_query($conn, $sql3);
          exit();
  
  
      }
  </code></pre>