I make an online store for PCP. When clicking on the button "add product to cart" - send a Get-request product id. The problem is that no more than one product is added to the basket (the one on which it was clicked), you click on another product - it is added, and the previous one disappears. need the help of experts in bringing the code to mind) so that the goods are added normally. Below is the code to add to the cart.

if(isset($_GET['add'])){ $_SESSION['id'] = $_GET['add']; require_once 'connection.php'; $link = mysqli_connect($host, $user, $password, $database) or die("Error!" . mysqli_error($link)); $link->set_charset("utf8"); $query = 'SELECT * FROM books WHERE id="' .$_SESSION['id']. '"'; $result = mysqli_query($link, $query) or die("Error!" . mysqli_error($link)); $row = mysqli_fetch_array($result); echo "<p>" .$row['author']. ' ' .$row['name']. ' ' .$row['price']." руб.</p>"; } else { echo "<p>В корзине - пусто</p>"; } 
  • and what you want to add, besides the clicked goods? oO - teran
  • 2
    I didn’t see the addition to this basket in this code, I see the output. - Yaroslav Molchan
  • Probably add 2 units of goods at once, then use the second field if(isset($_GET['num_goods'] > 1)){ //добавить х-товаров - Jean-Claude
  • This is not an add to cart code, but an output code for the selected item from the session. You go there in the same place to write the product ID, anyone who clicked on the user. - Daniel Protopopov

0