Jump to content

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

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

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;

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.