Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4582948
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:08:46+00:00 2026-05-21T21:08:46+00:00

I’m working on a college exercise about a shopping cart, I converted the POST

  • 0

I’m working on a college exercise about a shopping cart, I converted the POST values into an array, however when I echo these array values I get the 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 the 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'] as $key => $item) {
  echo $key, '. ', $item['item'], ' ', $item['quantity'], ' units';
}
*/

//Regreso a 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);

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T21:08:47+00:00Added an answer on May 21, 2026 at 9:08 pm

    That means that the $_SESSION[“lista”] array does not have an element for “item” or “quantity”.

    To see the full contents of $_SESSION you can use print_r():

    print_r($_SESSION);
    

    Note that in HTML this will not look nice, you’ll need to use “View Source” on your browser to see it in a good form.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.