So i made this database table called votes where i added 2 columns: likes and dislikes. In html i have 2 buttons: like button and dislike button. When i press the like button i want to increment the likes column value by 1, but i seem to be doing it wrong.
PHP:
if(isset($_POST['like'])) {
$sql = 'UPDATE votes';
$sql .= 'SET likes = likes + 1';
$sql .= 'WHERE id = 1';
// prepare
$stmt = $pdo->prepare($sql);
// execute
$result = $stmt->execute();
}
HTML:
<form action="" method="post">
<input type="submit" value="Like" name="like">
<input type="submit" value="Dislike" name="dislike"">
</form>
UPDATE votesSET likes = likes + 1WHERE id = 1- you can validate this by echoing$sql. Besides, such a short query can just be put in one line.