Jump to content

How to pass SESSION values to table ?


aveeva
 Share

Recommended Posts

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.

workout:

fetch_data.php return values.

https://snag.gy/IASCMZ.jpg

& values received

https://snag.gy/ojWxHe.jpg

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">
 <thead>
 <tr>
 <th>Voice Sku</th>
 <th>Voice Name</th>
 <th>Remove</th>
 </tr>
 </thead>

 <tbody>

 <?php
 session_start();
 $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;
 
 
            }   
 var_dump($_SESSION);    
 ?>

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

 </tbody>
</table>

 

Link to comment
Share on other sites

As I stated in the other forum where you posted you really need to see how a php script should/could be properly written.  Here is an example of how your script could/should look.  I don't know all of your planned actions with this but at least this shows you the proper format of a well-written script.

<?php
session_start();
//   Check if we have inputs
if(isset($_POST['voice_sku']) && 
	isset($_POST['voice_name']))
{
	//  Process the inputs here.
	$_SESSION['voice_sku'] = $_POST['voice_sku'];
	$_SESSION['voice_name'] = $_POST['voice_name'];
}
else
//   what to do if we DON'T have inputs?
{

}
//*****************************
// Done processing the inputs so time to do the output
//  Now build the output table
$code=<<<heredocs
  <table width="100%" cellpadding="6" cellspacing="0">
  <thead>
  <tr>
  <th>Voice Sku</th>
  <th>Voice Name</th>
  <th>Remove</th>
  </tr>
  </thead>
  <tbody>
  <!--  WHAT IS THIS ROW HERE FOR??? -->
  <!--  AND WHY A COLSPAN OF 5 WHEN YOU ONLY HAVE 3 HEADINGS???? -->
  <tr>
  <td colspan="5">
  <span style="float:right;text-align: right;">
  </span>
  </td>
  </tr>
  <!--  WHAT IS THIS ROW HERE FOR??? -->
  <!--  AND WHY A COLSPAN OF 5 WHEN YOU ONLY HAVE 3 HEADINGS???? -->
  <tr>
  <td colspan="5">
  <a href="index.php" class="button">Add More Items</a>
  <button type="submit">Update</button>
  </td>
  </tr>
  <!--   Put Input Values HERE  -->
  <form action='' method='POST'>
  <tr>
  <td>
  <input type='text' name='voice_sku' value="{$_SESSION['voice_sku']}">
  </td>
  <td>
  <input type='text' name='voice_name' value="{$_SESSION['voice_name']}">
  </td>
  <td>
  <input type='submit' name='btn' value='Remove'>
  </td>
  </tr>
  </form>
  </tbody>
  </table>
heredocs;
echo $code;
exit();	// are we done?

1 - start the session

2 - check for inputs

2a - handle missing inputs?

3 - process the inputs

4 - build the output 

 

No mixing of html code inside the php code.

Edited by ginerjm
  • Great Answer 1
Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.