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?
// 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->query($getFavoriteQuery);
if (mysqli_num_rows($favoriteQuery)) { ?>
<a href="#">Un-favorite</a>
<!-- UPDATE DATABASE MYSQLI QUERY -->
<?php } else { ?>
<a href="#">Favorite</a>
<!-- UPDATE DATABASE MYSQLI QUERY -->
<?php }
}
?>