Link to home
Start Free TrialLog in
Avatar of TLN_CANADA
TLN_CANADAFlag for Afghanistan

asked on

Storing Session Variables Question

Hey guys,

I'd like to know how to save these text boxes as session variables so that I can print them from other pages:

 <input name="bubble_idea1" type="text" id="bubble_idea1" size="37" style="display: none;">
 <input name="bubble_idea2" type="text" id="bubble_idea2" size="37" style="display: none;">
  <input name="bubble_idea3" type="text" id="bubble_idea3" size="37" style="display: none;">

Please can you give a sample of code on how to print these on another page so that I can test it.


Avatar of TLN_CANADA
Flag of Afghanistan image


I would also like to be able to store the value of the slider bar as a session variable. When I put it inside the form the slider bar disappears so if someone has a way to do this it would be greatly appreciated also.
I should mention that I want the session variables to be stored when the user moves to another page, in this case when the user selects "Add Body Sensations" from the dropdown.
Avatar of Julian Hansen
@Derek - should be similar to your other post
$_SESSION['bubble_idea1'] = $_POST['bubble_idea1']; // Sanitization required see not
$_SESSION['bubble_idea1'] = $_POST['bubble_idea2']; 
$_SESSION['bubble_idea1'] = $_POST['bubble_idea3']; 

Open in new window

Then in some other file

$bubble1 = empty($_SESSION['buble_idea1'])?''$_SESSION['buble_idea1'];

echo "Bubble1 : $bubble1";

Open in new window

Note on sanitization: direct access to the $_POST / $_GET / $_REQUEST vars is not recommended. It is good practice to santize the data from these sources before using them or you could open yourself to hacking exploits.
In answer to the question on the slider

To clarify - you say the slider does not work in the form - does that mean it does not display or it does not return a value to the posted script?

What slider are you using? Usually a slider would be used to set a hidden variable which is posted back but it depends on implementation.
Thank you! When I try to run the second page (calling the session variables) it gives the following error:

Parse error: syntax error, unexpected T_VARIABLE in /home/content/12/10022112/html/body.php on line 6

Just to be clear, I would like all three of the text boxes (bubble idea 1-3) in 3 different session variables so if I could test by printing each separate one that would be ideal.
Thank you for the tip about the sanitization. I have made a note of this and once I have the script working I will come back to this.

For the slider, the slider bar still appears but just the value in the text field (1-10) no longer changes when I move the slider.
The slider bar was found online and implemented with the help of another expert.
Ok but without knowing about how that slider works can't answer how to have its value post back to the form.
@TLN_CANADA: from this and your other question that I have seen it seems to me that you would benefit greatly from some structured learning about PHP.  A good place to start is here:

That book is worth every penny you might spend to purchase it, and worth the month of study it will take you to learn some of the basics of PHP and MySQL.  It is not in its fifth printing and it has been a permanent part of my professional library since Edition One.  Very readable with great examples and clarifying discussion, it comes with a downloadable code library that you can copy and modify for your own use.  The code library covers many of the most common programming tasks.

On the issue of sanitization (one aspect of security) these are invaluable learning resources.

Best of luck with your project, ~Ray
Thank you Ray for this helpful advice, I will check out this book.
Hi Julian,

I am working on the slider part and have this almost working correctly now.

For the text field variables on the page I still can't seem to pass them correctly.

I assume you made a small error in the above code and it should have been
$_SESSION['bubble_idea1'] = $_POST['bubble_idea1']; // Sanitization required see not
$_SESSION['bubble_idea2'] = $_POST['bubble_idea2']; 
$_SESSION['bubble_idea3'] = $_POST['bubble_idea3']; 

Open in new window

Then on another page it should be possible to access these variables like this?

echo $_SESSION['bubble_idea1];
echo $_SESSION['bubble_idea2];
echo $_SESSION['bubble_idea3];

I'm not sure why this isn't working for me.


I don't use a submit button on the page but rather on the dropdown menu when you select "Add Body Sensations" it takes you to another page. Could this be the reason why it's not working?
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you Julian, as I'm learning PHP at the moment, I'd like to get the basics of the site up and running for now so I'll just switch the dropbox to buttons so that it stores the session variables correctly.

Thank you for your help with this,

You are welcome