I have a problem while doing php session cart. I get the list of products from the database and each has own button "Add to cart". The problem is how to get any of them by button click to add into session?
<?php session_start();</br>
include_once 'dbconnect.php';
$_SESSION['cart']= array();
$sql="SELECT * FROM products ORDER BY name ASC";
$query=mysql_query($sql);?>
<a href="cart-display.php">Go To Cart</a>
I start a loop to output all products from database
<?php
while($row=mysql_fetch_array($query)){
?>
<form method="get">
<tr><td><?php echo $row['name'] ?></td>
<td><?php echo $row['description'] ?></td>
<td><?php echo $row['price'] ?></td>
<td><?php echo $elId= $row['id_product']?></td>
<td><button type="submit" name="btn-submit.<?php echo $elId;?>">Add To Chart</button></td>
</tr><br>
</form>
Then I try to get any of them by $_GET[], then try to push into array session. But it adds only the ast product because of the loop. Help please
<?php }
if(isset($_GET['btn-submit.$elId'])){
array_push($_SESSION['cart'], $elId);}?>
<?php session_start();</br>whaat. deprecated mysql functions and improper use of HTML within PHP.$query=mysql_query($sql);?> <a href="cart-display.php">Go To Cart</a>Is any of this even working?$_GET['btn-submit.$elId']what is this? Is this jquery selector? lol