?> </p> <p> <?php $collection_items = sort_collection($collection_items); $collection_count = count_collection($collection_items); echo 'Total Cards: ' . $collection_count; echo '<br>Total Likes: ' . $likes; ?> </p> <?php if ($owner && !$edit) { $editform = '<form method="get" action=".">' . '<input type="hidden" name="action" value="collection">' . '<input type="hidden" name="collectionid" value="' . $collection_id . '">' . '<input type="hidden" name="editview" value="true">' . '<input type="submit" value="Edit">' . '</form>'; echo $editform; } elseif (!$owner && isset($_SESSION['user_id'])) { $already_liked = check_if_liked($collection_id, $_SESSION['user_id']); if (!$already_liked) { $likeform = '<form method="post" action=".">' . '<input type="hidden" name="action" value="like">' . '<input type="hidden" name="collectionid" value="' . $collection_id . '">' . '<input type="hidden" name="userid" value="' . $_SESSION['user_id'] . '">' . '<input type="submit" value="Like this collection">' . '</form>'; echo $likeform; } else { echo 'You have already liked this collection'; } } ?> <table> <tr> <td class="collectionitemstd"> <?php if ($edit) { ?> <div class="collectionitemsform">
function like($collection_id, $user_id) { global $db; $exists = check_if_liked($collection_id, $user_id); if (!$exists) { $query = 'INSERT INTO collection_likes VALUES (NULL, :collection_id , :user_id)'; $statement = $db->prepare($query); $statement->bindValue(':collection_id', $collection_id); $statement->bindValue(':user_id', $user_id); try { $statement->execute(); return 'success'; } catch (PDOException $ex) { return 'error'; } } else { return 'error'; } }