I am implementing an Ajax Cart in PHP5 at core level with this code:
$resp = $cart->getDetails(filter_var($_POST["pid"], FILTER_SANITIZE_NUMBER_INT));
if($resp == "" OR $resp == null)
{
echo "Some Error!";
}
elseif($resp != "" || $resp != null)
{
while($row = $resp->fetch_assoc())
{
$itemArray[] = array(
$resp => array(
'name' => $row["product_name"],
'id' => $row["id"],
'discount' => $row["discount"],
'quantity' => 1,
'price' => $row["price"]
)
);
}
print_r($itemArray);
if(!empty($_SESSION["cart_item"]))
{
if(in_array($itemArray[], $_SESSION["cart_item"]))
{
foreach($_SESSION["cart_item"] as $k => $v)
{
if($itemArray[] == $k)
$_SESSION["cart_item"][$k]["quantity"] = $_POST["quantity"];
}
}
else
{
$_SESSION["cart_item"] = array_merge($_SESSION["cart_item"],$itemArray);
}
}
else
{
$_SESSION["cart_item"] = $itemArray;
}
}
I get the values properly in $resp
since I checked it using num_rows > 0
but there is an error, that cannot use [] for reading and that illegal offsets are used.
I am new to this thing and I have also tried modifying the code all over. Where am I going wrong?