Json_encode(array) insertion in db
MasTer.Men
-
loupix -
loupix -
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).")"
json
"INSERT INTO table_commande (id_commande,contenu_panier) VALUES(0,".json_encode($panier,JSON_FORCE_OBJECT).")"
1 réponse
-
$panier_json = json_encode($panier, JSON_FORCE_OBJECT);
"INSERT INTO table_commande (id_commande,contenu_panier) VALUES('0','$panier_json')"-
-
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 !
-