This is code to enable the "add to cart" button when the user logs in to my site. But I get an error:
Warning: Undefined variable $product_check_result in C:\xampp\htdocs\store\check_if_added.php on line 9
Could someone explain?
<?php
function check_if_added_to_cart($item_id){
require 'connection.php';
$user_id=$_SESSION['id'];
$product_check_query = $con->prepare("SELECT * from users_items WHERE item_id= :item_id AND user_id= :user_id AND status = :status");
$product_check_result->execute(array(':item_id' => $item_id, ':user_id' => $user_id, ':status' => 'Added to cart'));
$count = $product_check_result->fetchAll();
if(count($count) > 0) {
return true;
}
else {
return false;
}
}
?>