Bonjour, j'aimerais ajouter un système de panier relié à ma bdd, mais aucun tuto n'est assez clair pour moi, pouvez-vous m'aider en me disant ce qu'il faut concrètement ajouter à ce code pour obtenir un système d'ajout au panier complet svp ?

"<?php session_start(); 
if(!isset($_SESSION['panier'])){
    $_SESSION['panier'];
}

$db = new PDO('mysql:host=localhost;dbname=sitetrl;' , 'root' , '');
$q = $db->prepare("SELECT * FROM panier");
$q->execute();

?>

<!DOCTYPE html>
<html lang="eng">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="script.js" defer></script>
    <script src="https://kit.fontawesome.com/197f5fef08.js" crossorigin="anonymous"></script>
    <title>Real Lowers</title>
    <link rel="stylesheet" href="reset.css">
    <link rel="stylesheet" href="shop.css">
</head>

<body>

    <header>
        <h1><a href="index.php">rEALlOWERS</a></h1>
        <input type="checkbox" id="check"></input>
            <label for="check">
                <i class="fas fa-bars" id="toggle-button" ></i>
            </label>

        <nav class="cartlog">
                <nav class="menu">

                    <div><p><a href="index.php">HOME</a></p></div>
                    <div class="home"><p><a href="shop.php">SHOP</a></p></div>
                    <div><p><a href="index.php">CONTACT</a></p></div>
                    <div><p><a href="index.php">ABOUT US</a></p></div>

                </nav>
                    <p class="panier"><a href="panier.php"><i class="fas fa-shopping-cart"></i></a></p>

                    <?php if(!isset($_SESSION['email'])){?>

                        <p class="login"><a href="login.php"><i class="fas fa-user"></i> Log In</a></p>

                    <?php }else{ ?>

                        <div class="loginclass">
                            <p class="login1"><a href="logout.php"><i class="fas fa-user"></i> Log Out </a></p>
                            <p class="pseudo"><?php echo $_SESSION['pseudo']; ?> </p>
                        </div>

                    <?php } ?>

    </header>

    <section class="main">

            <h1 class="titre">Shop</h1>

            <div class="cards">
            <?php $products = $q->fetchAll(PDO::FETCH_OBJ) ?>
            <?php foreach($products as $product): ?>
                <div class="card"><a href="#">
                <img src=<?php echo $product->image; ?> alt="">
                <div class="cardinfo">
                    <h4 class="tshirt"><?php echo $product->name; ?></h4>
                    <h4 class="price"><?php echo number_format($product->price,2,',',' '); ?>€</h4>
                </div>
            <a class="add" href="#?id=<?= $product->id;?>&name=<?= $product->name;?>">Add to Cart</a>
            </a></div>
            <?php endforeach; ?>

    </section>

    <footer>

        <nav>
            <div class="menu">
                <p><a href="index.php">HOME</a></p>
                <p><a href="shop.php">SHOP</a></p>
                <p><a href="news.php">NEWS</a></p>
                <p><a href="contact.php">CONTACT</a></p> 
                <p><a href="aboutus.php">ABOUT US</a></p>  
            </div>
        </nav>

            <div class="copyright"> 
                <p>REAL LOWERS &copy; COPYRIGHT 2022 ALL RIGHTS RESERVED 
                <br> Designed by <a href="https://www.instagram.com/mateo.fs_/">@mateo.fs_</a></p>
            </div>    

    </footer>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>

</body>

</html>"

Ce que je veux

Ajouter un système d'ajout au panier en cliquant sur Add to cart

1 réponse


Salut, Est-ce qu'il y a une partie Ajax dans ce system de panier que tu veux ?