Json_encode(array) insertion in db

comment ajouter des variables session dans la base de donneés voila mon code

json

"INSERT INTO table_commande (id_commande,contenu_panier) VALUES(0,".json_encode($panier,JSON_FORCE_OBJECT).")"

1 réponse

  1. $panier_json = json_encode($panier, JSON_FORCE_OBJECT);

    "INSERT INTO table_commande (id_commande,contenu_panier) VALUES('0','$panier_json')"
    1. Merci pr la réponse loupix ! !j'ai un boutton commander comment je fais l'action sur le bouton pour lié ce code php avec le bouton
    2. tu peut faire un petit formulaire, et ensuite une redirection sur la page d'accueil
      moi j'ai mis bune variable session, ça me parait plus pratique

      ex :

      <form action="commander.php" method="post">
      <input type="hidden" name="id_produit" value="132" />
      <input type="button" name="commender" />
      </form>

      commander.php

      <?php
      if(isset($_POST['id_produit'])){
      $_SESSION['panier'][] = $_POST['id_produit'];

      $panier = $_SESSION['panier'];

      $panier_json = json_encode($panier, JSON_FORCE_OBJECT);

      "INSERT INTO table_commande (id_commande,contenu_panier) VALUES('0','$panier_json')"

      }else{
      echo "pas d'identifiant de produit";}
      header("Location:ancienne_page");
      ?>

      à tester !