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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:19:30+00:00 2026-05-24T13:19:30+00:00

I am having a problem with a script that controls an order system that

  • 0

I am having a problem with a script that controls an order system that i am creating.

The system contains a search feature that queries a user supplied string against products held in a mysql table, if the string matches part of an items description, then that item is returned as a result.

Now, The problem is this.

If a user searches a string that returns say 5 results.

Then the user decides they would like to add 3 of one result and 2 of another result.

They then click on order, which submits the form.

Here is where the problem appears, as only the first result that the user has entered a quantity for is added to the order.

The order should contain two items, one with a quantity of 3 and another with a quantity of 2. It is not doing that and i have no idea what is going wrong here.

Here is the code that controls the instance of the user clicking on the order button:

if (!isset($_SESSION['order']))
{
    $_SESSION['order'] = array();
}

if (!isset($_SESSION['quantity']))
{
    $_SESSION['quantity'] = array();
}

$productQuantities=$_POST['quantity'];
if (isset($_POST['action']) and $_POST['action'] == 'Order' and $productQuantities > 0)
{
foreach($productQuantities as $productId=>$quantityS)
{
        if ($quantityS > 0) 
            {
            $_SESSION['order']["$productId"] = $productId;
            $_SESSION['quantity']["$productId"] = $quantityS;
            header('Location: .');
            exit();
            }
}
}

Can anyone see where I am making a mistake in this?

Any input would be greatly appreciated, and I will supply any additional code on request.

Thanks!

  • 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-24T13:19:31+00:00Added an answer on May 24, 2026 at 1:19 pm

    You create a loop, but in the first iteration of that loop with a quantity, you send a Location header and exit the script execution. Clearly no more products can be added to $_SESSION once you terminate the script and send the visitor to another page.

    Don’t prematurely end the loop, and only send a (proper!) location header after you’ve finished.

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

Sidebar

Related Questions

I'm trying to debug a cons script, and the problem I'm having is that
Hi I am running the following script, the problem I am having is that
I'm having a problem with my python script. It's printing massive amounts of data
I'm having a problem with Python's subprocess.Popen method. Here's a test script which demonstrates
Given the following html table and script shown below I am having a problem
Okay so I am having this problem. I write up a script to be
I'm having an extremely weird problem with a PHP script of mine. I'm uploading
I have a rough php script that sees if a user has filled in
I'm having a problem with <%= obj.ClientID %> expansion, in a .ascx user control.
I'm having a problem that I believe has a simple solution. I'm writing a

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.