Facebook
From Unreliable Ibis, 3 Years ago, written in PHP.
Embed
Download Paste or View Raw
Hits: 109
  1. Plik służący za dodawanie produktów.
  2. <?php
  3.  
  4. if(isset($_GET['resetCart'])){
  5.  
  6. $_SESSION['cart'] = array();
  7.  
  8. }
  9. if(!isset($_SESSION['cart'])) {
  10. $_SESSION['cart'] = [];
  11. }
  12. if(isset($_POST['addToCart'])){
  13.  
  14. $_SESSION['cart'][] = array(
  15. 'name' => $_POST['name'],
  16. 'price' => $_POST['price'],
  17. 'quantity' => $_POST['quantity']
  18. );
  19.  
  20. }
  21. header("Location: twojGlownyPlik.php");
  22. ?>
  23.  
  24. twojGlownyPlik.php
  25. <?php session_start();?>
  26. <!DOCTYPE html>
  27. <html lang='pl'>
  28. <head>
  29. <title>Cart</title>
  30. </head>
  31. <body>
  32. <div>
  33. <form method="post" action="chhh.php">
  34. <input type="hidden" name="addToCart">
  35. <input type="text" name="price">
  36. <button type="submit">Dodaj</button>
  37. </form>
  38. <a href="NazwijJakSobieChcesz.php?resetCart">resetuj koszyk</a>
  39.  
  40.  
  41. </div>
  42. <div>
  43.  
  44. </div>
  45. <div>
  46. Podgląd koszyka:
  47. <h4><?php print_r($_SESSION['cart']);?></h4>
  48. </div>
  49. <button> <a href="index.php">wróć</a></button>
  50. </html>