By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,796 Members | 1,155 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,796 IT Pros & Developers. It's quick & easy.

How do I add values to my $_SESSION variable?

P: 1
Why is it that every time I run this code in a session that it does not add my new values to the session variable but it replaces the old value with the new.

Here is the Code:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. ##############
  4. # Link to DB #
  5. ##############
  6. require_once('DB_connect.php'); 
  7. $DB_connection = DB_connect(); 
  8.  
  9. ###################
  10. # Read input data #
  11. ###################
  12. $cat = "";
  13. $colin = "";
  14. $colout = "";
  15. $matin = "";
  16. $matout = "";
  17.  
  18. if(isset($_GET['cat'])) $cat = $_GET['cat'];
  19.  
  20.  
  21. $New="SELECT * FROM products WHERE catogory = '$cat' ORDER BY code";
  22. $result = mysql_query($New);
  23. $num=mysql_num_rows($result);
  24.  
  25.  
  26. $x = 0;
  27. $basket = array();
  28. while($x < $num){
  29.    $item = array();
  30.    $Code = mysql_result($result,$x,'code');
  31.    if ($_GET[$Code] != ""){
  32.          $Quant = $_GET[$Code];
  33.       $price = mysql_result($result,$x,'price');
  34.       $Catogory = mysql_result($result,$x,'catogory');
  35.       $Prod = mysql_result($result,$x,'product');
  36.       $Size = mysql_result($result,$x,'size');
  37.       if (isset($_GET['colin'.$Code])) $colin = $_GET['colin'.$Code];
  38.       if (isset($_GET['colout'.$Code])) $colout = $_GET['colout'.$Code];
  39.       if (isset($_GET['matin'.$Code])) $matin = $_GET['matin'.$Code];
  40.       if (isset($_GET['matout'.$Code])) $matout = $_GET['matout'.$Code];
  41.       $item[]=$Code;
  42.       $item[]=$Catogory;
  43.       $item[]=$Prod;
  44.       $item[]=$Size;
  45.       $item[]=$Quant;
  46.       $item[]=$price;
  47.       $item[]=$colin;
  48.       $item[]=$colout;
  49.       $item[]=$matin;
  50.       $item[]=$matout;
  51.  
  52.       $basket[]=$item;
  53.  
  54.       $_SESSION['basket'] = $basket;
  55.    }
  56.    $x++;
  57. }
  58. print_r($_SESSION['basket']);
  59. ?>
  60.  
Is $_SESSION[ ] not an array that you can add to the end?
Jun 24 '07 #1
Share this Question
Share on Google+
1 Reply


pbmods
Expert 5K+
P: 5,821
Heya, gogelpot. Welcome to TSDN!

Why is it that every time I run this code in a session that it does not add my new values to the session variable but it replaces the old value with the new.
Set $basket to $_SESSION['basket'] instead of array(). [Line 27]
Jun 24 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.