Schlo_50 Posted February 4, 2008 Share Posted February 4, 2008 Hello, Im creating a 'select item and confirm order' script. I have items displayed on a page in the following format: I have the item id and the quantity collect in their own arrays and now want to transfer that information from products.php into final.php where the user can view their selected items and then click 'finalize' which will then input the data into a database. From the snippet below can someone suggest how i might go about doing the above? products.php if (isset($_POST['update']) && ($_POST['update']==="Submit Order")) { $orderid = array(); $quantity = array(); foreach($_POST['orderid'] as $id){ $orderid[] = $id; $quantity[] = $_POST['quantity'][$id]; } $orderid = implode(',', $orderid); $quantity = implode(',', $quantity); final.php <?php $_GET[$orderid] = $orderid; $_GET[$quantity] = $quantity; print "$orderid"; print "quantity"; ?> <form name="the_form2" id="the_form2" method="post" action="<?php $_SERVER[php_SELF]; ?>"> <?php print "$orderid<br />"; print "quantity"; ?> <input name="update" type="submit" value="Submit Order" /> I am thinking that i need some kind of '$_GET' in final.php but have no idea how to exchange the information for the user to confirm their items are correct. Any ideas? If you have any questions you need answering before you can help please do ask! Thank-you Quote Link to comment Share on other sites More sharing options...
Cep Posted February 4, 2008 Share Posted February 4, 2008 Try to avoid passing data from page to page via POST and GET. Look at using sessions instead. At the top of your scripts (be wary of any includes you use) place the following, <?php session_start(); ?> Now from your script you will be able to assign values to session variables and then on your other script read them in, <?php // assign values $_SESSION['myName'] = $myvar; //read in if (isset($_SESSION['myName'])) { $myvar = $_SESSION['myName']; } else { // create a default if session is not found $myvar = ""; } ?> These are basic examples, so read up on sessions Quote Link to comment Share on other sites More sharing options...
Schlo_50 Posted February 4, 2008 Author Share Posted February 4, 2008 Ok, I forgot about sessions! I took products.php and added: if (isset($_POST['update']) && ($_POST['update']==="Submit Order")) { $orderid = array(); $quantity = array(); foreach($_POST['orderid'] as $id){ $orderid[] = $id; $quantity[] = $_POST['quantity'][$id]; } $orderid = implode(',', $orderid); $quantity = implode(',', $quantity); $_SESSION['quan'] = $quantity; //added $_SESSION['ord'] = $orderid; //added } And on final.php i used: <?php if (isset($_SESSION['quan']) && isset($_SESSION['ord'])) { $quantity = $_SESSION['quan']; $orderid = $_SESSION['ord']; } print "$quantity<br /><br />$orderid<br />"; ?> The Result is 'Array' 'Array', not the values. Do i need to explode them or something? Thanks for the help (Again..) lol Quote Link to comment Share on other sites More sharing options...
Aureole Posted February 4, 2008 Share Posted February 4, 2008 I would imagine so, yes. Quote Link to comment Share on other sites More sharing options...
Cep Posted February 5, 2008 Share Posted February 5, 2008 As you have copied two arrays to the two session variables, they now become arrays themselves. So in order to print or echo out the information you would need to iterate through the array. Something like this, <?php foreach($quantity as $quan) { echo "{$quan}<br /><br />"; } ?> Looking at your code though I have to ask why you are creating two separate arrays? I can see your data becoming a little disjointed, why not store the Order ID as the Key name and quantity as the key value? 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.