Bonjour,
Voila je rencontre un petit problème avec mon code.
Décrivez ici votre code ou ce que vous cherchez à faire
<?php
require_once("inc/init.inc.php");
// payer le panier
if(isset($_GET['action']) && $_GET['action'] == 'reserver')
{
// calcul du montant total
$montant_total = 0;
$taille = sizeof($_SESSION['panier']['id_produit']);
for($i = 0; $i < $taille; $i++)
{
$montant_en_cours = $_SESSION['panier']['quantite'][$i]*$_SESSION['panier']['prix'][$i];
$montant_total += $montant_en_cours;
}
$id_membre = $_SESSION['membre']['id_membre'];
$id_produit = $_SESSION['produit']['id_produit'];
// enregistrement de la commande table commande
$pdo->query("INSERT INTO commande (id_membre, id_produit, date_enregistrement) VALUES ($id_membre, $id_produit, NOW())");
unset($_SESSION['panier']);
}
// vider le panier
if(isset($_GET['action']) && $_GET['action'] == 'vider')
{
// si l'utilisateur a cliqué sur le bouton vider le panier
unset($_SESSION['panier']); // on met cette action en haut car plus bas on peut recréer le panier, sinon on ne pourra pas
}
// Ajout d'un article dans le panier
if(isset($_POST['ajout_panier']))
{
// cet indice provient du bouton ajouter au panier depuis fiche_article.php
if(isset($_POST['id_produit']) && ($_POST['quantite']))
{
$produit = $pdo->prepare("SELECT * FROM produit LEFT JOIN salle ON produit.id_salle = salle.id_salle WHERE produit.id_produit = :id_produit");
$produit->bindParam(":id_produit", $_POST['id_produit'], PDO::PARAM_STR);
$produit->execute();
$info_produit = $produit->fetch(PDO::FETCH_ASSOC);
$id_produit = $_POST['id_produit'];
$quantite = $_POST['quantite'];
$prix = $info_produit['prix'] * 1.2; // on multiplie le prix par 1.2 pour récupérer le tva (20%)
$titre = $info_produit['titre'];
$_SESSION['panier']['id_produit'][] = $id_produit;
$_SESSION['panier']['quantite'][] = $quantite;
$_SESSION['panier']['prix'][] = $prix;
$_SESSION['panier']['titre'][] = $titre;
header("location:" . URL . "commande.php"); // pour éviter un nouvel ajout lors du raffraichissement de page (F5)
}
}
// création du panier
//$creation_panier();
// création du panier
function creation_panier()
{
if(!isset($_SESSION['panier']))
{
$_SESSION['panier'] = array();
$_SESSION['panier']['titre'] = array();
$_SESSION['panier']['id_produit'] = array();
$_SESSION['panier']['quantite'] = array();
$_SESSION['panier']['prix'] = array();
var_dump($_SESSION['panier']);
var_dump($_SESSION);
}
}
require_once("inc/header.inc.php");
require_once("inc/nav.inc.php");
?>
<div class="container">
<?php
echo $msg;
?>
<div class="starter-template">
<h1><span> Votre réservation</span></h1>
<p class="lead"></p>
</div>
<?php var_dump($_SESSION); ?>
<?php ?>
<?php var_dump($_POST); ?>
<div class="row">
<div class="col-sm-12">
<hr/>
<a href="?action=vider" class="btn btn-danger">Annulez la réservation</a>
<?php if(utilisateur_est_connecte()){ ?>
<a href="?action=payer" class="btn btn-success">Confirmer la réservation</a>
<?php
}else{
?>
<br/><span> Veuillez vous <a href="connexion.php">Connecter</a> ou vous <a href="inscription.php"> Inscrire</a> afin de confirmer votre réservation</span>
<?php } ?>
<hr/>
</div>
<div class="col-sm-6">
<table class="table table-bordered">
<tr>
<th>Article</th>
<th>Titre</th>
<th>Quantité</th>
<th>Prix ttc</th>
</tr>
<?php
// une boucle pour afficher tous les articles du panier dans ce tableau
// on récupère la taille du tableau
$taille = sizeof($_SESSION['panier']['id_produit']);var_dump($_SESSION); die();
for($i = 0; $i < $taille; $i++)
{
echo '<tr>';
echo '<td>' . $_SESSION['panier']['id_produit'][$i] . '</td>';
echo '<td>' . $_SESSION['panier']['titre'][$i] . '</td>';
echo '<td>' . $_SESSION['panier']['quantite'][$i] . '</td>';
echo '<td>' . $_SESSION['panier']['prix'][$i] . '€</td>';
echo '</tr>';
}
?>
</table>
</div>
</div>
</div><!-- /.container -->
<?php
require_once("inc/footer.inc.php");
Bonsoir à tous! Je travaille sur un projet en php que je dois faire pour mon centre de formation. J'ai un pbm avec mon fichier 'panier'. Il y a une faute qui sort: Notice: Undefined index: panier in C:\wamp64\www\sallea\commande.php on line 129 Normalement la variable 'panier' existe plus haut, quand je déclare $_SESSION, je bloque sur cela. Est-ce que quelqu'un pourrait m'aider à trouver ma faute, s'il vous plaît.
Notice: Undefined index: panier in C:\wamp64\www\sallea\commande.php on line 117
Bonjour,
Avant d'afficher, il te faut tester si ton panier contient des articles ou non.
if( isset( $_SESSION['panier'] ) ) {
$taille = sizeof($_SESSION['panier']['id_produit']);
for($i = 0; $i < $taille; $i++){
echo '<tr>';
echo '<td>' . $_SESSION['panier']['id_produit'][$i] . '</td>';
echo '<td>' . $_SESSION['panier']['titre'][$i] . '</td>';
echo '<td>' . $_SESSION['panier']['quantite'][$i] . '</td>';
echo '<td>' . $_SESSION['panier']['prix'][$i] . '€</td>';
echo '</tr>';
}
} else {
echo '<tr><td colspan="4">Le panier est vide</td></tr>';
}
$taille = sizeof($_SESSION['panier']['id_produit']);var_dump($_SESSION); die();
for($i = 0; $i < $taille; $i++)
{
echo '<tr>';
echo '<td>' . $_SESSION['panier']['id_produit'][$i] . '</td>';
echo '<td>' . $_SESSION['panier']['titre'][$i] . '</td>';
echo '<td>' . $_SESSION['panier']['quantite'][$i] . '</td>';
echo '<td>' . $_SESSION['panier']['prix'][$i] . '€</td>';
echo '</tr>';
}
j'ai l'impression que ton $_SESSION['panier'] est supprimé avant que tu le listes.
Ajoute un echo avant chaque unset
<?php
echo "je unset $_SESSION['panier'] en le vidant/réservant";
=> adapte en fonction de l'unset que tu fais.
ça me sort la même chose: Notice: Undefined index: panier in C:\wamp64\www\sallea\commande.php on line 27
Call Stack
quand je fais ça
C:\wamp64\www\sallea\commande.php:4:
array (size=2)
'membre' =>
array (size=8)
'id_membre' => string '3' (length=1)
'pseudo' => string 'admin' (length=5)
'nom' => string 'Dupont' (length=6)
'prenom' => string 'Marc' (length=4)
'sexe' => string 'm' (length=1)
'email' => string 'admin@mail.fr' (length=13)
'date_enregistrement' => string '2017-06-28 14:39:16' (length=19)
'statut' => string '1' (length=1)
'commande' =>
array (size=0)
empty
et toujours le panier undefined
C'est logique puisque ton panier n'est même pas dans le $_SESSION avant même de commencer ton script.
Donc il faut savoir pourquoi il n'existe pas.
Peut-être du à une erreur dans l'enregistrement
sûrement, car les données ne s'enregistrent pas dans la base de données, sauf que je ne vois pas du tout où est ma faute. Suis une vraie débutante, c'est le premier projet après une semaine de cours (