954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Getting session variables between different actions

Hello,
I managed starting a session and store some data when a user login to the system. The user can edit his/her prifile by clicking on edit, then some of the data will show in the edit form. Now I have the form with empty fields and I need to get the users data from the session to show in the edit form. Now I have a function for every action for example: login(), edit().., I set the $_SESSION variabls for email and password inside function login, I need to get them back inside function edit, but I get error undefined index Email: this is the code for setting $_SESSION inside login():

$_SESSION['Email']=$HTML['email'];// I was able to print the values
$_SESSION['Password']=$HTML['password'];

I tried this inside function edit():

echo $_SESSION['Email'];

I got error: Undefined index: Email

Thanks in advance.

rse
Light Poster
28 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

im not really clear what you mean
i think you mean you
want to put the session variable into a form so user can edit it

<?php

echo "<input name=\"email\" type=\"text\" value='".$_SESSION['Email']."' />";


?>
HITMANOF44th
Posting Whiz in Training
283 posts since Apr 2009
Reputation Points: 24
Solved Threads: 33
 

also from the looks of it you are setting a array form the email
are the values filling in the array the right way when you run print_r

echo print_r($HTML);
HITMANOF44th
Posting Whiz in Training
283 posts since Apr 2009
Reputation Points: 24
Solved Threads: 33
 

Do you have session_start() function at the beginning of your script? If not it won't work. Check the $_SESSION contents with

print_r($_SESSION);


and compare it with the value of $HTML

print_r($HTML);
broj1
Posting Whiz
359 posts since Jan 2011
Reputation Points: 29
Solved Threads: 43
 

I get empty array when I print $_SESSION. I started the session, and I set the variables inside function login. I tried to get them back from inside function edit, but I got empty values.

rse
Light Poster
28 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

Sorry not empty. I got Undefined index.

rse
Light Poster
28 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

Maybe you should post complete code so we can have a look at it.

broj1
Posting Whiz
359 posts since Jan 2011
Reputation Points: 29
Solved Threads: 43
 

I bet broj1 is right - sounds like no session_start(). Even if the HTML vars were empty, the session vars should exist.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,796 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

Thanks, it was one of the set_ini functions.

rse
Light Poster
28 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You