aveeva Posted July 10, 2019 Share Posted July 10, 2019 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> Quote Link to comment Share on other sites More sharing options...
ginerjm Posted July 10, 2019 Share Posted July 10, 2019 (edited) 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 July 10, 2019 by ginerjm 1 Quote Link to comment Share on other sites More sharing options...
aveeva Posted July 10, 2019 Author Share Posted July 10, 2019 @ginerjm I am learning stage in PHP, really thanks to your steps, Now working good, As i said already this is for add to cart, how to each data to my_cart.php, my page : How to save more than one value? Quote Link to comment Share on other sites More sharing options...
Barand Posted July 10, 2019 Share Posted July 10, 2019 Didn't I answer this already a few days ago? 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.