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

  • Home
  • SEARCH
  • 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 7544305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:38:29+00:00 2026-05-30T08:38:29+00:00

For eg I have this code on the main page. <?php session_start(); $_SESSION[‘order’]=array(); ?>

  • 0

For eg I have this code on the main page.

<?php
session_start();
$_SESSION['order']=array();

?>
<form name="orderform" method="post" action="e.php">
Product Catalog
<table border="1">
<tr>
    <td>Product</td>
    <td>Price</td>
    <td>Quantity</td>
</tr>
<?
    for($i=0;$i<6;$i++){
        echo '<tr>';
        echo '<td><input type=hidden name="product" value="'.$i.'"> Product     '.$i.'</td>';
        $price=rand(1,10);
        echo '<td><input type=hidden name="price"     value="'.$price.'">$'.$price.'</td>';
        echo '<td><input type=text name="quantity"></td>';
        echo '<tr>';        
    }
?>
</table>
<br>
<input type="submit" name="submit" value="submit">
</form>

I have a multidimensional Session array, $_SESSION[‘order’] and I’m trying to save this order form of 6 product items, along with its price and quantity, so it can be retrieved on the following page after POST method is actioned.

ie on e.php file

<?php

session_start();

$_SESSION['order'][] = array('product'=>$_POST['product'],
                                'price'=>$_POST['price'],
                                'quantity'=>$_POST['quantity']);
var_dump($_SESSION['order']);

if(count($_SESSION['order'])>0){
    foreach($_SESSION['order'] as $order){
        echo "<p>Product = ".$order['product']."</p>";
        echo "<p>Price = ".$order['price']."</p>";
        echo "<p>Quantity = ".$quantity['quantity']."</p>";
    }
}
?>

But the result I’m getting on e.php is I only get the last item of the order page, but not the other previous five. Did I do something wrong here? What are your thoughts?

  • 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-30T08:38:31+00:00Added an answer on May 30, 2026 at 8:38 am

    You’re _POSTing multiple fields with the same name property, so the $_POST variable will contain only the final unique names that you’re posting up. You can either create unique names for each input, or you can post up the fields as an array. Unique names would look like this:

    <?
        for($i=0;$i<6;$i++){
            echo '<tr>';
            echo '<td><input type=hidden name="product'.$i.'" value="'.$i.'"> Product     '.$i.'</td>';
            $price=rand(1,10);
            echo '<td><input type=hidden name="price'.$i.'"     value="'.$price.'">$'.$price.'</td>';
            echo '<td><input type=text name="quantity'.$i.'"></td>';
            echo '<tr>';        
        }
    ?>
    

    And then you’d need to loop through the post array and add it to session array:

    <?php
    $i=0;
    while(isset($_POST['product'.$i])){
       $_SESSION['order'][] = array('product'=>$_POST['product'],
                                    'price'=>$_POST['price'],
                                    'quantity'=>$_POST['quantity']);
       $i++;
    }
    ?>
    

    You can also send it up as an array:

    <?
        for($i=0;$i<6;$i++){
            echo '<tr>';
            echo '<td><input type=hidden name="product[$i]" value="'.$i.'"> Product     '.$i.'</td>';
            $price=rand(1,10);
            echo '<td><input type=hidden name="price[$i]"     value="'.$price.'">$'.$price.'</td>';
            echo '<td><input type=text name="quantity[$i]"></td>';
            echo '<tr>';        
        }
    ?>
    

    And get it out like this:

    <?php
    foreach($_POST['product'] as $key => $value){
       $_SESSION['order'][] = array('product'=>$_POST['product'][$key],
                                    'price'=>$_POST['price'][$key],
                                    'quantity'=>$_POST['quantity'][$key]);
    } 
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an iframe on my main page, and this iframe uses php code
i have this code in indexSucces.php //some html for the main page <td width='48%'
On my main page I have this jquery code which does an ajax call
I have this structure in my page. Secondary form works, and main does not.
I have this code that goes to form.php instead of pulling the echoed php
I have this code #include <iostream> using namespace std; int main(int argc,char **argv) {
This is the code I have: Sub Main() Dim dts As New DataSet Dim
I have a code that looks like this: int main () { fstream file;
Say, I have a code snippet like this: public static void main(String[] args) {
I built a classified. In the main/index.php page, I have many categories like cars,

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.