Hello everyone I am working on an eCommerce site and need some help. Currently, I have some products that are on display for sale. By each item there is a box where a person can enter how much of the product they want and then press the button to add it to the cart. I had one item get added into the cart just fine. However, when I try add another item into the cart it either doesn't get added or it adds the first item again and not the new product I clicked on.
Here is code to show the products:
<?php
$consoles = getConsoles($db);
if(!empty($consoles)){
foreach($consoles as $key=>$value){
?>
<form method="post" action="index.php">
<p><?php echo $consoles[$key]["name"]; ?></p>
<p><?php echo $consoles[$key]["description"]; ?></p>
<img src="<?php echo $consoles[$key]["image"]; ?>">
<p><?php echo "$" . $consoles[$key]["price"]; ?></p>
<p><?php echo $consoles[$key]["quanity"]; ?></p>
<p><?php echo $consoles[$key]["limted_Edition"]; ?></p>
<p><?php echo $consoles[$key]["year_Published"]; ?></p>
<input type="text" name="q" value="1" size="2" />
<input type="hidden" name="serial" value=<?php echo $consoles[$key]["serialNumber"]; ?> >
<input type="submit" name="add" value="Add to Cart" />
<?php
}
}
?>
</form>
Here is my code for added to a cart:
include 'phpfunctions/functions.php';
include 'open_db.php';
$number = 1;
if (isset($_POST['add'])){
$number++;
$cartID = $number;
$username = "Twili";
$itemid = NULL;
$serialNumber = $_POST['serial'];
$quanity = $_POST['q'];
addToCart($db, $cartID, $username, $itemid, $serialNumber, $quanity
);
}
Thank you for any help!
Aucun commentaire:
Enregistrer un commentaire