session - PHP: Array => Undefined Index -


i'm working on college exercise shopping cart, converted post values array, when echo these array values following message:

notice: undefined index: item in line 40 notice: undefined index: quantity in line 40 

here's line 40:

echo "1. ".$_session['lista']['item']." ".$_session['lista']['quantity']." unidades".", ".$_session['lista']['price']." crc."; 

here's full script:

    <?php  session_start();  //obtengo la lista $lista[]= $_session['lista'];  //guardo un valor en la lista /* $articulo= $_post['articulo']; $cantidad= $_post['cantidad']; $codigo= $_post['codigo']; */  //listado $articulos = array(    'papaya' => 500, 'banano' => 50, 'mango' => 150,    'leche' => 500, 'cafe' => 1200, 'mantequilla' => 300,   'pan' => 450, 'jugo' => 780, 'mani' => 800,   'yogurt' => 450, 'cerveza' => 550, 'vino' => 2500,   );  $_session['lista'] = array( 'item' => ($_post['articulo']),  'quantity' => ($_post['cantidad']), 'code' => ($_post['codigo']), );  //precio $precio = $articulos[($_session['lista']['item'])] * $_session['lista']['quantity'];  $_session['lista'] = array('price' => $precio,);   //listado echo  "<b>listado de compra</b></br>";   echo "1. ".$_session['lista']['item']." ".$_session['lista']['quantity']." unidades".", ".$_session['lista']['price']." crc.";  /*foreach($_session['lista'] $key => $item) {   echo $key, '. ', $item['item'], ' ', $item['quantity'], ' units'; } */  //regreso la lista $_session['lista'] = $lista;    var_dump($_session); $lista;  echo "</br> <a href='index.html'>volver al indice</a>";  //session_destroy = elimina todo  //imprimo lo que hay en session var_dump($_session);  ?> 

that means $_session["lista"] array not have element "item" or "quantity".

to see full contents of $_session can use print_r():

print_r($_session); 

note in html not nice, you'll need use "view source" on browser see in form.


Comments