diff --git a/lib/meme.php b/lib/meme.php
index 40a7e53..e356cb8 100644
--- a/lib/meme.php
+++ b/lib/meme.php
@@ -28,8 +28,8 @@ function renderMeme(int $id, int $authorId, string $title, string $textContent,
$meme_out = str_replace('__TEMPLATE_MEME_DELETE_BUTTON__', (isModerator() || $_SESSION['ID'] == $authorId) ? "" : '', $meme_out);
$meme_votes = calculateNetVotes($id);
- $meme_upvote = isLoggedIn() ? "" : '';
- $meme_downvote = isLoggedIn() ? "" : '';
+ $meme_upvote = isLoggedIn() ? "" : '';
+ $meme_downvote = isLoggedIn() ? "" : '';
$meme_out = str_replace('__TEMPLATE_MEME_VOTES_NUMBER__', $meme_votes, $meme_out);
$meme_out = str_replace('__TEMPLATE_MEME_UPVOTE__', $meme_upvote, $meme_out);
@@ -99,13 +99,15 @@ function deleteMeme(int $memeID): array
return $out;
}
-function voteMeme(int $memeID, bool $isUpvote): array
+function voteMeme(int $memeID, int $isUpvote): array
{
global $mysqli;
$out = ["Status" => "Fail"];
- $vote = $isUpvote ? 1 : 0;
+ if ($isUpvote != 1) {
+ $isUpvote = 0;
+ }
$memeVoteConn = $mysqli->prepare('INSERT INTO MemeVotes (MemeID, UserID, isUpvote) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE isUpvote = VALUES(isUpvote)');
- $memeVoteConn->bind_param('iii', $memeID, $_SESSION['ID'], $vote);
+ $memeVoteConn->bind_param('iii', $memeID, $_SESSION['ID'], $isUpvote);
$memeVoteConn->execute();
if ($memeVoteConn->affected_rows > 0) {
$out['Status'] = 'Success';