I have a problem with arrays, I'm not so new in PHP but I have a little experience with manipulating complex arrays like one I need now.
I'm building shopping cart and my idea of cart is database row which every user will have and shopping process should go something like this
When user buys a product if product doesn't exist in the cart script should add product to the cart like e.g. 1=1 or in array words $cart = [ [1]=>'1' ] which means product ID1 quantity 1, now if product already exist in the cart script should just update quantity like e.g. 1=2 and so on for higher quantity.
This is my poor attempt to accomplish aforementioned
PHP
<?php session_start();
require_once('config.php');
$member_id = '1'; // Test data
$pr_id = filter_input(INPUT_POST, 'pr_id', FILTER_SANITIZE_STRING); // Sending ID with jQuery/AJAX which works fine of course
$pr_qty = '1'; // Start quantity
$up_qty = '5'; // Test data
try {
$getCart = $conn->prepare("SELECT cart FROM members WHERE member_id = :member_id ");
$getCart->bindParam(':member_id', $member_id);
$getCart->execute();
$cart = $getCart->fetch(PDO::FETCH_ASSOC);
if(array_key_exists($pr_id, $cart)) {
$cart[$pr_id] = $up_qty . ',';
}
else {
$cart[$pr_id] = $pr_qty . ',';
}
$updateCart = $conn->prepare("UPDATE members SET cart = :cart WHERE member_id = :member_id ");
$updateCart->bindParam(':member_id', $member_id);
$updateCart->bindParam(':cart', implode($cart));
if($updateCart->execute()) {
echo '1';
}
}
catch(PDOException $error) {
echo 'Error: ' . $error->getMessage();
}
$conn = null;
?>
Later on I should be able to retrieve product ID's and quantities from database but when the time comes...
I'm working about three days on this and I'm hopeless, I searched everywhere, find many tutorials on multidimensional arrays but I think that my problem is a little unique or I'm just stupid enough and can't solve it.
Thanks everyone in advance, I hope we'll solve it together, more brains = more knowledge = solution ;)

var_dump($cart)?$conna mysqli object or a pdo object?NULLbut when I echo it with implode it shows1,1,1,tryyou've used variables within your prepare statement. Prepared statements (or at least in mySQLi::prepare) do not allow variable injection this way to prevent SQL injection so I believe. try using bindParam to add your variables to the statement.implodeit shows data in the cart butarray_key_existsdoesn't work.