I'm hitting my head to a wall... This is a fraction of my code:
$stmt = $db->prepare("SELECT vote,id FROM votes WHERE post_id = ? AND user_id = ? ");
$stmt->bind_param('ii', $post_id, $user_id);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($result, $vote_id);
$stmt->fetch();
$num_rows = $stmt->num_rows;
$stmt->close();
if ($num_rows>=1)
{
if ($result!==$vote)
{
$stmt = $db->prepare("UPDATE votes SET vote = ? WHERE id=?");
$stmt->bind_param('ii', $vote, $vote_id);
$stmt->execute();
$stmt->close();
}
else if ($result==$vote)
{
$stmt = $db->prepare("UPDATE votes SET vote = 0 WHERE id=?");
$stmt->bind_param('i', $vote_id);
$stmt->execute();
$stmt->close();
}
}
No errors are shown, the script works just fine until it reaches ELSE IF part. It doesn't update although $vote value is the same as in a database.
else **if**just anelse, its either going to be match or not