I want to add to database user_id and fav_id. But only if they both together are not recorded yet. I did something wrong in my code becayse it all the time adds it. Why does that happen?
<?php
include '../connect.php';
$fav_id = $_POST['fav_id'];
$user_id = $_POST['user_id'];
$number = $pdo-> query('SELECT COUNT(*) FROM favourites WHERE user_id = :user_id AND fav_id = fav_id ');
if ($number == 0) {
$pdo->exec("INSERT INTO `favourites` (`fav_id`, `user_id`) VALUES (" . $fav_id . "," . $user_id . ")");
}
else die();
?>