title: WORDPRESS: Create a function which updates database on click
body: <p>I have created a function but I have come to a hurdle, I want to make the if/else hrefs clickable and I need them to add/remove entries into the database, whats the best way to do this?</p>
  
  <pre><code>    // FAVORITE
  function favorite($user_id, $post_id) {
  
      // DB Connection
      $mysqli = mysqli_connect("localhost", "???", "???", "???");
  
      // Check Favorite
      $getFavoriteQuery = "
          SELECT  *
          FROM    wp_favorites
          WHERE   user_id = $user_id
          AND     post_id = $post_id";
  
      $favoriteQuery = $mysqli-&gt;query($getFavoriteQuery); 
  
      if (mysqli_num_rows($favoriteQuery)) { ?&gt;
  
          &lt;a href="#"&gt;Un-favorite&lt;/a&gt;
  
          &lt;!-- UPDATE DATABASE MYSQLI QUERY --&gt;
  
      &lt;?php } else { ?&gt;
  
          &lt;a href="#"&gt;Favorite&lt;/a&gt;
  
          &lt;!-- UPDATE DATABASE MYSQLI QUERY --&gt;
  
      &lt;?php }
  
  }
  ?&gt;
  </code></pre>