title: Query SQL without refreshing the page using Ajax
body: <p>Objective: Query SQL without refreshing the page using Ajax.</p>
  
  <p>I have Like/Dislike buttons that function perfectly as a form and submit input, however, the form refreshes the page.</p>
  
  <p>I have no clue how to make an Ajax call that connects my 'liker.php' (below) to operate within my main page via a class/id div click or button.</p>
  
  <pre><code>$.ajax({
    type: "POST",
    url: "liker.php",
    data: ???
    success: ???
    ...............
  </code></pre>
  
  <p>I've read some tutorials and looked for answers, but I'm still stumped.</p>
  
  <p><strong>liker.php</strong>:</p>
  
  <pre><code>//LIKE FIELD
  if (isset($_POST['like'.$id])) {
    if (!in_array("$id", $like_explode)) {
      if (!in_array("$id", $dislike_explode)) {
        mysqli_query($db, "UPDATE likes SET pid_like=CONCAT(pid_like,',$id') WHERE user_id='$user_id'");
        mysqli_query($db, "UPDATE comments SET likes=(likes+1) WHERE id='$id'");
      }
      else
      {
        $new_dislike_string = str_replace(",$id", '', $dislike_string);
        mysqli_query($db, "UPDATE likes SET pid_dislike='$new_dislike_string' WHERE user_id='$user_id'");
        mysqli_query($db, "UPDATE likes SET pid_like=CONCAT(pid_like,',$id') WHERE user_id='$user_id'");
        mysqli_query($db, "UPDATE comments SET likes=(likes+1) WHERE id='$id'");
        mysqli_query($db, "UPDATE comments SET dislikes=(dislikes-1) WHERE id='$id'");
      }
    }
  }
  //DISLIKE FIELD
  if (isset($_POST['dislike'.$id])) {
    if (!in_array("$id", $dislike_explode)) {
      if (!in_array("$id", $like_explode)) {
        mysqli_query($db, "UPDATE likes SET pid_dislike=CONCAT(pid_dislike,',$id') WHERE user_id='$user_id'");
        mysqli_query($db, "UPDATE comments SET likes=(dislikes+1) WHERE id='$id'");
      }
      else
      {
        $new_like_string = str_replace(",$id", '', $like_string);
        mysqli_query($db, "UPDATE likes SET pid_like='$new_like_string' WHERE user_id='$user_id'");
        mysqli_query($db, "UPDATE likes SET pid_dislike=CONCAT(pid_dislike,',$id') WHERE user_id='$user_id'");
        mysqli_query($db, "UPDATE comments SET dislikes=(dislikes+1) WHERE id='$id'");
        mysqli_query($db, "UPDATE comments SET likes=(likes-1) WHERE id='$id'");
      }
    }
  }
  //LIKE-DISLIKE FIELD END
  </code></pre>