Harley1979 Posted May 20, 2007 Share Posted May 20, 2007 Hi, I'm having a problem with losing data for an array I have stored as a session. I need some help here. Here is my code: First page: <?php echo " <form action='wholefoods-placeorder.php' method='post'> <div id='tableContainer'> <div id='tableContentHead'></div> <div id='tableContentMain'>"; $mysqlCat = mysql_query("SELECT * FROM productCategory"); while($catRow = mysql_fetch_array($mysqlCat)){ $getCat = $catRow['category']; echo "<h3 class='newfont'>{$getCat}</h3>"; $catID = $catRow['id']; $mysqlProd = mysql_query("SELECT * FROM products WHERE categoryID = '$catID'"); echo " <table> <thead> <tr> <th class='i'>Product</th> <th class='ii'>Size</th> <th class='iii'>Price</th> <th class='iv'>Qty</th> </tr> </thead>"; $i = 1; while($prodRow = mysql_fetch_array($mysqlProd)){ echo " <tbody> <tr> <td>".$prodRow['item']."</td> <td>".$prodRow['size']."</td> <td>£".$prodRow['price']."</td> <td><input type='text' id='qty' name='qty[".$prodRow['id']."]' maxlength='1' size='1' /></td> <input type='hidden' name='product[".$prodRow['item']."]' value='".$prodRow['item']."'></tr> </tbody>"; } echo " <tfoot> <tr> <td colspan='4'></td> </tfoot> </table>"; } echo "<input type='submit' id='submit' name='submit' value='Next' /> </div> <div id='tableContentFoot'></div> </form>"; ?> Second page: // set sessions $_SESSION['qty'] = $_REQUEST['qty']; $qty = $_SESSION['qty']; //$product = $_REQUEST['product']; foreach ($qty as $key => $value) { if (isset($qty[$value])) { echo $value.", "; } } It seems to pick it up and write out on screen ok on the second page. It is after that when going to another url that it seems to lose the data. I'm lost, any help would be great Thanks Harley Quote Link to comment https://forums.phpfreaks.com/topic/52249-session-array-losing-data-problem/ Share on other sites More sharing options...
Barand Posted May 20, 2007 Share Posted May 20, 2007 You need to call session_start() at top of any page using $_SESSION Quote Link to comment https://forums.phpfreaks.com/topic/52249-session-array-losing-data-problem/#findComment-257787 Share on other sites More sharing options...
Harley1979 Posted May 20, 2007 Author Share Posted May 20, 2007 Yes, this has also been done. As I say the session picks up first time round but then on moving to another page the session data is lost. This is specificaly session data containing arrays, all other session data is fine. Regards Harley Quote Link to comment https://forums.phpfreaks.com/topic/52249-session-array-losing-data-problem/#findComment-257856 Share on other sites More sharing options...
MadTechie Posted May 20, 2007 Share Posted May 20, 2007 You need to call session_start() at top of any page using $_SESSION Quote Link to comment https://forums.phpfreaks.com/topic/52249-session-array-losing-data-problem/#findComment-257860 Share on other sites More sharing options...
Harley1979 Posted May 20, 2007 Author Share Posted May 20, 2007 Am I right in saying that all you have to do to set a session is to write session_start() at the top of your page, and then $_SESSION['name'] = "Peter"; to assign its value, regardless of wether or not you are holding an array as its value? Quote Link to comment https://forums.phpfreaks.com/topic/52249-session-array-losing-data-problem/#findComment-257917 Share on other sites More sharing options...
MadTechie Posted May 21, 2007 Share Posted May 21, 2007 not 100% correct you need to have session_start(); before any output to allow you to read or write to $_SESSION's so if your page as $_SESSION in it then you need to have session_start(); before any output Quote Link to comment https://forums.phpfreaks.com/topic/52249-session-array-losing-data-problem/#findComment-257951 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.