low-rider Posted April 4, 2007 Share Posted April 4, 2007 hi, i have two phps..... products.php and overview.php im tryin to use session to pass some variables from products.php to overview.php and whatever i try only the first variable gets set whereas the rest of them do not! //products.php <?php session_start(); $_SESSION["BagName"] = $BagName; --------------- this is the name of he product (BAG) $_SESSION["QBag"] = $QBag; ---------------- the quantity of the bag (1) ?> //overview.php <?php session_start(); $BagName = $_SESSION["BagName"]; ^^^^^^^^^^^^ same as above $QBag = $_SESSION["QBag"]; ^^^^^^^^^^^^ save as above ?> <? echo $_SESSION["BagName"].$_SESSION["QBag"]; ?> whatever i do i can only get the BagName to echo! what am i doing wrong??? Quote Link to comment https://forums.phpfreaks.com/topic/45601-session-helpweird-problem/ Share on other sites More sharing options...
low-rider Posted April 4, 2007 Author Share Posted April 4, 2007 this is what i get when i do a print_r($_SESSION) Array ( [bagName] => Bag [QBag]=>) Quote Link to comment https://forums.phpfreaks.com/topic/45601-session-helpweird-problem/#findComment-221426 Share on other sites More sharing options...
kenrbnsn Posted April 4, 2007 Share Posted April 4, 2007 How is the variable $QBag set in the first script? Ken Quote Link to comment https://forums.phpfreaks.com/topic/45601-session-helpweird-problem/#findComment-221433 Share on other sites More sharing options...
low-rider Posted April 4, 2007 Author Share Posted April 4, 2007 How is the variable $QBag set in the first script? Ken it is set via a text box where its initial value is set to 1 Quote Link to comment https://forums.phpfreaks.com/topic/45601-session-helpweird-problem/#findComment-221434 Share on other sites More sharing options...
kenrbnsn Posted April 4, 2007 Share Posted April 4, 2007 Please post the code where it is set. Ken Quote Link to comment https://forums.phpfreaks.com/topic/45601-session-helpweird-problem/#findComment-221436 Share on other sites More sharing options...
low-rider Posted April 4, 2007 Author Share Posted April 4, 2007 Quantity<font face="Times New Roman" size="3"> </font> <!--webbot bot="Validation" s-data-type="Number" s-number-separators=",." i-maximum-length="2" s-validation-constraint="Greater than or equal to" s-validation-value="1" s-validation-constraint="Less than or equal to" s-validation-value="10" --><input type="text" name="QBag" size="2" maxlength="2" value="1"></p> Quote Link to comment https://forums.phpfreaks.com/topic/45601-session-helpweird-problem/#findComment-221439 Share on other sites More sharing options...
kenrbnsn Posted April 4, 2007 Share Posted April 4, 2007 That is the code for the form, we need to see your PHP code that uses the values from the form. Please post the code between tags. Ken Quote Link to comment https://forums.phpfreaks.com/topic/45601-session-helpweird-problem/#findComment-221440 Share on other sites More sharing options...
low-rider Posted April 4, 2007 Author Share Posted April 4, 2007 im not sure what u r asking for as i dont have any [code/] tags ??? Quote Link to comment https://forums.phpfreaks.com/topic/45601-session-helpweird-problem/#findComment-221441 Share on other sites More sharing options...
kenrbnsn Posted April 4, 2007 Share Posted April 4, 2007 Post your code. Put the tag in front of your code and the tag after your code. These are tags used by this forum to format the code so it's more readable. Ken Quote Link to comment https://forums.phpfreaks.com/topic/45601-session-helpweird-problem/#findComment-221444 Share on other sites More sharing options...
low-rider Posted April 4, 2007 Author Share Posted April 4, 2007 sorry...just got what u meant. it is <? if (isset($_SESSION['BagName'])) { echo $_SESSION['BagName']; } if (isset($_SESSION['QBag'])) { echo $_SESSION['QBag']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/45601-session-helpweird-problem/#findComment-221447 Share on other sites More sharing options...
kenrbnsn Posted April 4, 2007 Share Posted April 4, 2007 That is the code that displays what's in the $_SESSION. We need to see the code that processes the form and sets stores the values in the $_SESSION array. Ken Quote Link to comment https://forums.phpfreaks.com/topic/45601-session-helpweird-problem/#findComment-221452 Share on other sites More sharing options...
low-rider Posted April 4, 2007 Author Share Posted April 4, 2007 if this is not it then i dont have that, which in turn causes the problem //products.php <?php session_start(); if(isset($BagName)){ $_SESSION["BagName"] = $BagName; } $_SESSION["QBag"] = $QBag; ?> //overview.php <?php session_start(); $BagName = $_SESSION["BagName"]; $QBag = $_SESSION["QBag"]; ?> this is all i have for setting the $SESSIONS!!!! Quote Link to comment https://forums.phpfreaks.com/topic/45601-session-helpweird-problem/#findComment-221457 Share on other sites More sharing options...
kenrbnsn Posted April 4, 2007 Share Posted April 4, 2007 You are assuming that register_globals are enabled, which is probably not the case. In "products.php" change your code to: <?php session_start(); if(isset($_POST['BagName'])){ $_SESSION["BagName"] = $_POST['BagName']; } $_SESSION["QBag"] = $_POST['QBag']; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/45601-session-helpweird-problem/#findComment-221463 Share on other sites More sharing options...
low-rider Posted April 4, 2007 Author Share Posted April 4, 2007 just did what u said and still have the same problem! ??? Quote Link to comment https://forums.phpfreaks.com/topic/45601-session-helpweird-problem/#findComment-221467 Share on other sites More sharing options...
kenrbnsn Posted April 4, 2007 Share Posted April 4, 2007 At the start of that script add: <?php echo '<pre>' . print_r($_POST,true) . '</pre>'; ?> This will dump the values that are being returned to your script from the form. Ken Quote Link to comment https://forums.phpfreaks.com/topic/45601-session-helpweird-problem/#findComment-221478 Share on other sites More sharing options...
low-rider Posted April 4, 2007 Author Share Posted April 4, 2007 is this supposed to go to the very beginning on "products.php"? Quote Link to comment https://forums.phpfreaks.com/topic/45601-session-helpweird-problem/#findComment-221492 Share on other sites More sharing options...
kenrbnsn Posted April 4, 2007 Share Posted April 4, 2007 Right after the "session_start()" <?php <?php session_start(); echo '<pre>' . print_r($_POST,true) . '</pre>'; if(isset($_POST['BagName'])){ $_SESSION["BagName"] = $_POST['BagName']; } $_SESSION["QBag"] = $_POST['QBag']; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/45601-session-helpweird-problem/#findComment-221495 Share on other sites More sharing options...
low-rider Posted April 4, 2007 Author Share Posted April 4, 2007 that sort of works! now the thing is that i have 3 products, a bag, a hat and a ball! i changed eerything to what u said for all three! when i print the session i get Array ( [bagName] => Bag [ballName] => [HatName] => [QBag] => 1 [QHat] => 1 [QBall] => 1 ) which shows that it picks up the bag and all the quantity fields but not the rest of the names! why?? Quote Link to comment https://forums.phpfreaks.com/topic/45601-session-helpweird-problem/#findComment-221501 Share on other sites More sharing options...
gazalec Posted April 4, 2007 Share Posted April 4, 2007 try assigning the sessions to variables i had a similar problem with multiple sessions try something like <?php session_start(); if(isset($_POST['BagName'])){ $_SESSION["BagName"] = $_POST['BagName']; } $_SESSION["QBag"] = $_POST['QBag']; $bag = $_SESSION['BagName']; $quantity = $_SESSION['QBag']; echo $bag." ".$quantity; ?> Quote Link to comment https://forums.phpfreaks.com/topic/45601-session-helpweird-problem/#findComment-221509 Share on other sites More sharing options...
low-rider Posted April 4, 2007 Author Share Posted April 4, 2007 ^^^^^^^^^^^ doesnt work mate! it still prints just the Bag and all 3 quantities! ??? Quote Link to comment https://forums.phpfreaks.com/topic/45601-session-helpweird-problem/#findComment-221540 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.