How to pass SESSION values to table?

I am under developing PHP add to cart without DB, so that i am using SESSION, actually get data from fetch_data.php data to my_cart.php using the POST method, successfully retun the values,

After receiving the post data how can i convert to display like a table.


fetch_data.php return values.

& values received

Here is my my_cart.php :

// FYI -> Here i am using only two fields :  voice_sku & voice_name 

<table width="100%" cellpadding="6" cellspacing="0">
 <th>Voice Sku</th>
 <th>Voice Name</th>


 $voice_sku = '';
 $voice_name = '';

 if(isset($_POST['voice_sku'])&& isset($_POST['voice_name']))
 // print_r($_POST);
 // die();
 $voice_sku = $_POST['voice_sku'];
 $voice_name = $_POST['voice_name'];
 $_SESSION['voice_sku'] = $voice_sku;
 $_SESSION['voice_name'] = $voice_name;

 <td colspan="5">
 <span style="float:right;text-align: right;">
 <!--  -->
 <td colspan="5">
 <a href="index.php" class="button">Add More Items</a>
 <button type="submit">Update</button>


the PHP command to output to the HTML is echo.

Hi OP,
There are several problems with what you are doing.

  1. Do not create variables for nothing. Just asking, where are you learning from that is teaching you to do this?

  2. Assuming you have a proper form somewhere, you need to check the REQUEST METHOD. An empty form submitted will always have the fields isset, so checking if they are is pointless. You need to trim the POST array and then check for empty.

  3. You have a submit button with no opening or closing form.

  4. Do not dump a bunch of code in the middle of a table. Do your processing first and then use the output where it needs to go. Php should be at top of page, HTML below it.

  5. You were already given good code examples in another forum for a similar post that show you what to do which you have not integrated. If your not going to implement the correct coding that people take their time to write for you then don’t waste our time posting the same bad code to multiple forums.

1 Like