Bonjour,
J'essaie de faire un panier en php en utilisant les sessions.
J'ai une page page panier.php qui affiche les produits ajoutés au panier, mais j'obtiens l'erreur suivante:
Notice: Undefined offset: 1 in C:\wamp\www\Nouveau dossier\panier.php on line 22
Notice: Undefined offset: 1 in C:\wamp\www\Nouveau dossier\panier.php on line 26
Voici mon code:
Code PHP :
<?php
session_start();
$n = count($_SESSION['panier']);
if($n != 0) {
$n++;
}
if ((isset($_POST['id']))and (isset($_POST['quantite'])))
{
$_SESSION['panier'][$n]['id']=$_POST['id'];
$_SESSION['panier'][$n]['quantite'] = $_POST['quantite'];
}
$n = count($_SESSION['panier']);
for ($i = 0; $i<$n; $i++) {
?>
<br/>
<?php
echo $_SESSION['panier'][$i]['id'];
?>
<br/>
<?php
echo $_SESSION['panier'][$i]['quantite'];
?>
<br/>
<?php
}
?>
Les lignes 22 et 26 sont les suivantes:
Code PHP :
echo $_SESSION['panier'][$i]['id'];
echo $_SESSION['panier'][$i]['quantite'];
Merci d'avance pour toute aide.