Can i combine these two queries in one single query that will check if user already liked one particular post, and if not then insert data.
In first query i check if row with that user id and and that post id exists
$existCheck = $con->prepare("SELECT * FROM likes WHERE user=:user AND post=:post");
$existCheck->execute(array(':user'=>$user_id, ':post'=>$post_id));
$existNumber = $existCheck->rowCount();
And in second query i insert data if row doesn't exist
if($existNumber == 0) {
$insertLike = $con->prepare("INSERT INTO likes (user, post) VALUES(:user, :post)");
$insertLike->execute(array(':post'=>$post_id, ':user'=>$user_id));
}
And $user_id = $_SESSION['user_id'];
and $post_id
is unique id of each post.