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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:31:33+00:00 2026-06-06T12:31:33+00:00

I have a small issue with sessions. I have built a small shopping cart-esque

  • 0

I have a small issue with sessions. I have built a small shopping cart-esque section on a site which does nearly what I want it to do. One issue is that when I visit my basket and have NO items in it, it throws up an error:

Warning: Invalid argument supplied for foreach() in /home/andydownham/site.com/wp-content/themes/theme/basket.php on line 28

I guess it needs something like 'if items are in cart' > use normal code > else display 'sorry there are no items in your cart' it’s just I don’t know how exactly how to implement this.

Here is the code I am using to store things into the session

<?php
session_start();
//var_dump($_POST);
//print_r($_SESSION);
$_SESSION['event_orders'][] = $_POST['event_id'];
?>

and this is the code I am using on the basket page:

<?php
session_start();

foreach($_SESSION['event_orders'] AS $event_id){
    echo '<div class="grad basket">';

    echo '<div class="thumb">';
    $EM_Event = em_get_event($event_id);
    echo $EM_Event->output('#_EVENTIMAGE{72,72}');
    echo '</div>';
    echo '<div class="basket-title"><h2>';
    echo '<a href="';
    $EM_Event = em_get_event($event_id);
    echo $EM_Event->output('#_EVENTURL');
    echo '">';
    $EM_Event = em_get_event($event_id);
    echo $EM_Event->output('#_EVENTNAME');
    echo '</a>';
    echo '</h2>';
    echo '<div class="basket-dates"> Dates:';
    $EM_Event = em_get_event($event_id);
    echo $EM_Event->output('#_EVENTDATES');
    echo '</div></div>';
    echo '<div class="klear"></div>';
    echo '<input type="submit" class="remove" value="remove" />';
    echo '</div>';
    echo '<br/>';
}
?>
  • 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-06T12:31:36+00:00Added an answer on June 6, 2026 at 12:31 pm

    You need to make sure that $_SESSION['event_orders'] exists (even if it’s an empty array). You can check that with the empty function (which will catch the empty array as well):

    if (empty($_SESSION['event_orders'])) {
      // Cart is empty
    } else {
      foreach(...) {
        ...
      }
    }
    

    You need to be careful with empty, though. These things are also considered “empty” (from the manual):

    *  "" (an empty string)
    * 0 (0 as an integer)
    * 0.0 (0 as a float)
    * "0" (0 as a string)
    * NULL
    * FALSE
    * array() (an empty array)
    * var $var; (a variable declared, but without a value in a class)
    

    Especially note that the string containing “0” is considered empty! That means that if you, in the future somewhere, have a HTML form where the user may input values and the user puts in the number 0, that field will be considered “empty” by this function. That is not always what you want. In this case, though, it is useful for checking the “emptiness” of your array.

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

Sidebar

Related Questions

i have a small issue which my text field insist to inhert the CSS
I have a small issue. Sometimes when I debug an application I want to
I have a small issue with which I'm struggling. I need to align a
I have a small issue with a method that should save the text contained
I have a small issue(for lack of a better word) with MySQL db. I
I am just new to programming in Unix and have a small issue that
can anyone help, i have a small issue, i have an interface and also
I have run into a small issue in my program. I have a class
everything is working fine with my jqgrid except a small issue. i have defined
I have a small issue with the ZXingWidgetController , if I present the controller

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.