so I'm trying to store shopping cart items by there ID. Once this happens a button needs to appear "Remove from Cart", if I click this button a new button will appear "Add to Cart" but I'm a little bit lost on it from this point. Im new on here so please excuse my mistakes. My code is below:
session_start();
$items[] = $_POST['add'];
if (isset($_POST['add'])) {
$_SESSION['cart'][]=$_POST['add'];
} else if (isset($_POST['remove'])) {
unset ($_SESSION['cart'][$_POST['remove']]);
}
foreach($vend as $vendID=> $items) {
echo "<form action='vend.php' method='post'>";
echo "<article id ='vend-$vendID'>";
echo "<h1 class = 'item-h1' id = 'h1'>{$items['title']}</h1>";
echo "<div class ='item-no'>";
echo "<p class = 'pro-id'><b>Product ID: </b>{$vendID}</p></div>";
echo "</div>";
echo "<div class ='img-div'>";
echo "<img src=../images/{$items['img']} alt='' height='196' width='200'></div>";
echo "<div class='item-p'>";
echo "<p>{$items['desc']}</p></div>";
echo "<div class='pricing'>";
echo "<p><b>Price: $</b>{$items['price']}</p></div>";
//echo "<button name='add' type='submit' value='$vendID'>Add to Cart</button>";
if(isset($_POST['add']) && ($_SESSION['cart'] == $vendID)) {
echo "<button name='remove' type='submit' value='$vendID'>Remove from Cart</button>";
}
else {
echo "<button name='add' type='submit' value='$vendID'>Add to Cart</button>";
}