Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2019
    Thanked 0 Times in 0 Posts

    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 :

    PHP Code:
    // 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 '';

    $_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>


  2. #2
    Senior Coder deathshadow's Avatar
    Join Date
    Feb 2016
    Keene, NH
    Thanked 517 Times in 504 Posts
    where you're doing your var_dump, replace with an "echo" statement using the values. I HIGHLY suggest you use htmlspecialchars to prevent people sending JavaScript as content, resulting in what's known as a XSS exploit.

    $safeSku = htmlspecialchars($_SESSION['voice_sku']);
    echo '
    		<th scope="row">', $safeSku, '</th>
    		<td>', htmlspecialchars($_SESSION['voice_name']), '</td>
    				value="', $safeSku, '"
    				title="Mark for Removal"
    Is roughly how I'd handle that. I'd store the specialchars version in the variable since it's used more than once. Good rule of thumb? Used only once, no extra variable. Used more than once, extra variable. The checkbox is structured in a way your "update" button should be able to handle mass removals. SErver side that would send you $_POST['remove'] as an array containing all the SKU's to remove. $_POST['remove'] will not exist if no checkboxes are selected.

    I guessed wildly, but assumed batch removal would be more desirable than one at a time.

    Note, whatever that span is for, don't do that! Style in markup == BAD since that's not HTML's job, and if you want alignment that's nothing you can't apply to the TD (so far).

    Also, the "add more" and "update" aren't really part of the tabular data, I would put it after the table instead of before. That or I'd put into into a TFOOT since again, it's not part of the table's "body' of data.

    ... and don't forget to scope="col" your THEAD's TH.
    “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies.” – C.A.R. Hoare, The 1980 ACM Turing Award Lecture

  3. #3
    Senior Coder benanamen's Avatar
    Join Date
    Oct 2015
    Thanked 164 Times in 159 Posts
    OP has already been answered on other forums and so far has no implemented the things he was already told.
    To save time, lets just assume I am almost never wrong.

    The XY Problem
    The XY problem is asking about your attempted solution (X) rather than your actual problem (Y). This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.

    Make A Donation https://www.paypal.me/KevinRubio


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts