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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:07:49+00:00 2026-05-30T02:07:49+00:00

The issue is the results from local host are not matching up with the

  • 0
  • The issue is the results from local host are not matching up with the live site when pushed by FTP. The
    below code seems make me believe the array is not be created
    properly on the server. In addition, it is doing some funky stuff, as seen below. The error is “Cannot use a scalar value as an array” on line 97, or $_SESSION[“count”][$i] +=1. Do you see the reason why? Or is there a different mistake I made?

  • To summarize the code, the following session arrays make up the core of the shopping cart: $_SESSION[‘item_id’][$i], $_SESSION[‘size’][$i],
    $_SESSION[‘price’][$i], $_SESSION[‘count’][$i] … and they all correlate to one another. Therefore a check is done to see if the combination exists, if so it appends the count, if not, adds the item combination for the first time.

Local Host

In Stock: 3
Distinct Item Count: 3

Array ( [0] => 1 [1] => 2 [2] => 2 ) Item Array: 1
Array ( [0] => S [1] => M [2] => L ) Size Array: 1
Array ( [0] => 15 [1] => 20 [2] => 20 ) Price Array: 1
Array ( [0] => 15 [1] => 35 [2] => 17 ) Count Array: 1

Quantity Increased to 18 

1 
S 
15
15


2 
M 
20
35


2 
L 
20 
18 

|3 ($1285) 

Live Site – First Add

In Stock: 5
0


1
M
20
1

|1 ($20)

Live Site – Second Add

In Stock: 5
Distinct Item Count: 1

1Item Array: 1
MSize Array: 1
300Price Array: 1
1Count Array: 1


Warning: Cannot use a scalar value as an array in /public_html/shop/helper/addtocart.php on line 97
Quantity Increased To

1
M
2


|1 ($0)  

Code

    if (isset($_SESSION["item_id"]) && is_array($_SESSION["item_id"])){
        echo "Distinct Item Count: " . count($_SESSION["item_id"]);
        echo "<br/>";
        echo "<br/>";
        echo "Item Array: ";
        print_r($_SESSION["item_id"]);
        echo "<br/>";
        echo "Size Array: ";
        print_r($_SESSION["size"]);
        echo "<br/>";
        echo "Price Array: ";
        print_r($_SESSION["price"]);
        echo "<br/>";
        echo "Count Array: ";
        print_r($_SESSION["count"]);
        echo "<br/>";
        echo "<br/>";
    }

    //check for current product combination in visitor's shopping cart content

    //find count in cart
    if (!isset($_SESSION["item_id"])){
      $count = 0;
      }else{
        $count = count($_SESSION["item_id"]);
      }
    echo $count;
    echo "<br/>";

    if ($count == 0){

        //declare arrays
        $_SESSION["item_id"] = array();
        $_SESSION["size"] = array();
        $_SESSION["price"] = array();
        $_SESSION["count"] = array();
        $_SESSION["total"] = array();

        //add first item to cart
        $_SESSION["item_id"][] = $item_id;
        $_SESSION["size"][] = $size;
        $_SESSION["price"][] = $price;
          //fundraiser and corporate
          if (($_SESSION["acctype"] == 2 || $_SESSION["acctype"] == 3) && isset($_SESSION['userid'])){
              //update count, add 100
              $_SESSION["count"][] = 100;
              }
          else{
              $_SESSION["count"][] = 1;
          }
    }else{
        $flag=0;
        $i=0;
        while ($i <= $count){
           if( ($_SESSION["item_id"][$i] == $item_id) && ($_SESSION["size"][$i] == $size) ){
           //fundraiser and corporate
              if(!isset($_SESSION["acctype"]) || $_SESSION["acctype"] == 1){
                 //update by one
                  $_SESSION["count"][$i] +=1;
                }
              elseif(isset($_SESSION['userid']) && ($_SESSION["acctype"] == 2 || $_SESSION["acctype"] == 3)){
                    //update count, add 100
                    $_SESSION["count"][$i] +=100;
                }
              else{
                  echo "Hmm";
                }
              //update cart stats
              echo notify('Quantity Increased To' . ' ' . $_SESSION["count"][$i]);
              //was there combination match?
              $flag = 1;
              }
        $i++;
        }
        if($flag == 0){
                  $_SESSION["item_id"][] = $item_id;
                  $_SESSION["size"][] = $size;
                  $_SESSION["price"][] = $price;
                    //fundraiser and corporate
                    if (($_SESSION["acctype"] == 2 || $_SESSION["acctype"] == 3) && isset($_SESSION['userid'])){
                        //update count, add 100
                        $_SESSION["count"][] = 100;
                    }else{
                    $_SESSION["count"][] = 1;
                    }
         }
    }
  • 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-30T02:07:50+00:00Added an answer on May 30, 2026 at 2:07 am

    Short answer: Check to see if register_globals is enabled on your live server using var_dump(ini_get('register_globals')) or phpinfo() . If register_globals is enabled, the preferable solution is to disable register globals—it leads to security problems and as of PHP 5.3 is deprecated.

    Longer answer: ‘Cannot use a scalar value as an array’ means that a scalar value (e.g. number) exists in the variable that you are referencing as an array. I do not see anywhere that you assign a scalar directly to $_SESSION["count"].

    However, if register_globals is enabled $count would become a reference to $_SESSION["count"], which means $count = 0 would be setting $_SESSION["count"] to a scalar. Again, the preferable solution would be to disable register_globals, but a workaround would be to rename the $count variable to something else.

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

Sidebar

Related Questions

I had an issue with my search not return the results I expect. I
I have problem with connecting to Sql Server from my local machine. Seems like
UDATE3: found the issue. See the answer below. UPDATE2: It seems I might have
I am havin a query as SELECT * FROM Issue I, Condition C, Result
I am using Oracle SQL Developer, but I am having an issue seeing results
I'm having an issue extracting a substring in SQL query results. Here's the situation:
Here's the issue: I am using R to run some statistical analysis. The results
Is this a known issue? I had trouble finding any search results. When iterating
I need to issue multiple $.get requests, process their responses, and record the results
Please help me out on this explode() function issue. I am getting unexpected results

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.