Pleinair Pleinair - 5 months ago 6x
MySQL Question

Mysql database table column value increment not working

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.


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();


<form action="" method="post">
<input type="submit" value="Like" name="like">
<input type="submit" value="Dislike" name="dislike"">


It's a typo, you are missing spaces between each row.

$sql = 'UPDATE votes ';  
$sql .= 'SET likes = likes + 1 ';    
$sql .= 'WHERE id = 1';