Jump to content

Session help.....weird problem!


low-rider

Recommended Posts

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???

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/45601-session-helpweird-problem/
Share on other sites

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>

 

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!!!!

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

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??

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;

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.