= mysqli_connect($hostname, $username, $password, $databasename);
$query = "SELECT likes FROM posts WHERE id=$id";
$result = mysqli_query($connection, $query);
$array = mysqli_fetch_assoc($result);
$likes = $array['likes'];
if ($isLiked == true) {
$updateQuery = "UPDATE posts SET likes = $likes++";
} else {
$updateQuery = "UPDATE posts SET likes = $likes--";
}
mysqli_query($connection, $updateQuery);
} catch (mysqli_sql_exception $e) {
echo "failed\t$e";
}
could you please tell me what is this codes problem ???
You are updating without a condition.
Your code allows SQL injection attacks. Please read this https://phpdelusions.net/sql_injection
Обсуждают сегодня