I am Getting Products from database and now i am trying to get that specific product that add by user in my session but i am unable to do that here is the my code
<div class="card" style="width: 18rem;margin: 5px;">
<img src="<?php echo $item['Pimage'] ?>" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title"><?php echo $item['Pname'] ?></h5>
<p class="card-text"><?php echo $item['Pdesc'] ?></p>
<P><?php echo $item['Pprice'] ?>PKR</P>
<form action="" method="post">
<input type="hidden" value="<?php $cid=$item['ID'] ?>">
<input type="submit" class="btn btn-warning" name="cid" value="Add to Cart">
<!-- <a href="sample.php" class="btn btn-warning">ADD To Cart</a>-->
</form>
<?php
if(isset($_POST['cid']))
{
$name=$item['Pname'];
$pdesc=$item['Pdesc'];
$price=$item['Pprice'];
$cartArray = array(
'name'=>$name,
'price'=>$pdesc,
'image'=>$price);
$_SESSION['cart']=$cartArray;
header('location:sample.php');
}?>
</div>
</div>
on next page
<?php
session_start();
foreach($_SESSION['cart'] as $val)
{
print_r($val);
}
here is my front end
![enter image description here](https://i.stack.imgur.com/54gYZ.png)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…