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 7867347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:41:22+00:00 2026-06-03T00:41:22+00:00

I have a site that stores an array in sessions. Items are added to

  • 0

I have a site that stores an array in sessions.
Items are added to the array and the array is looped through to display the items.

On my local XAMPP it is working fine but now I’ve uploaded it, it is showing some odd behaviour.

My array should look like this:

Array
(
    [bag] => Array
        (
            [0] => Array
                (
                    [item_id] => 4
                    [stock_id] => 7
                    [quant] => 1
                )
         )
)

And after I add an item it does but after a few clicks it turns in to this:

Array
(
    [bag] => 1
)

with the error:

Warning: Invalid argument supplied for foreach() in /public_html/xxx.php on line xx

Is there some session setting I should be aware of for the php .ini configuration or something similar?
(I’m using Hostgator if that helps)


A simplified way I’m adding items to the array-

function AddBag()
{
//get info
    $item_id   = $_POST['item_id'];
    $quant      = $_POST['quant];
    $stock_id  = $_POST['stock_id];

    if (isset($_SESSION['bag'])) {$bag_array = $_SESSION['bag'];}
    else                         {$bag_array = array();}

//add item into array
    $new_item = array("item_id" => $item_id, "stock_id" => $stock_id, "quant" =>         $quant);
    array_push($bag_array, $new_item);

//update session with new array
    $_SESSION['bag'] = $bag_array;
}
  • 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-06-03T00:41:23+00:00Added an answer on June 3, 2026 at 12:41 am

    Think I’ve found the answer myself-

    I have a foreach loop like this:

    foreach ($_SESSION['bag'] as $bag) {$bag_num = $bag_num + $bag['quant'];
    

    This worked fine testing it on my local XAMPP but on my hosting it wasn’t having it.
    Changing it to:

    foreach ($_SESSION['bag'] as $bagx) {$bag_num = $bag_num + $bagx['quant'];
    

    seems to work though.

    I can see why there would be a conflict but not WHY it works on one or on the other, any ideas?

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

Sidebar

Related Questions

I have a login setup on a site that stores login information in PHP's
I have a site that displays other sites through an iframe on certain pages.
I have a site that makes use of GET variables to determine what to
We have a site that is serving some RSS feeds, and we'd like to
I have a site that uses a large centered background image, which naturally loads
I have a site that I put: <body onload="ajaxLoad()" > I have a Javascript
I have a site that allows people to upload large video files in various
I have a site that features some pages which do not require any post-back
I have a site that has 2 DIV tags, one floats left the other
I have a site that will require a login by the users. The client

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.