...

View Full Version : session variable trouble



opelit
11-01-2006, 01:39 PM
Hi!
I am working on a school alumni website. I want to save username in session variable when user Login. I am a new user to php.
My problem matches with one of your previous post, but not completely.

session1.php:
<?php
session_start();
session_register("session");
$session['id']=session_id();
$session['username']=$userid;
?>

session2.php:
<?php
error_reporting(E_ALL);
echo "The variable stored in the session is ".$_SESSION['username'];
?>

The error is:
Notice: Undefined index: username in c:\inetpub\wwwroot\phplogincontrol\signup-login\welcome.php on line 29
The variable stored in the session is

Thanks in advance.

bigtiger
11-01-2006, 03:00 PM
session1.php:
<?php
session_start();
session_register("session");
$session['id']=session_id();
$session['username']=$userid;
?>

session2.php:
<?php
error_reporting(E_ALL);
echo "The variable stored in the session is ".$_SESSION['username'];
?>

The error is:
Notice: Undefined index: username in c:\inetpub\wwwroot\phplogincontrol\signup-login\welcome.php on line 29
The variable stored in the session is


You should notice this. Is it ?

opelit
11-02-2006, 10:01 AM
Hi!
First of all Thanks for your quick reply!
Now i have made respective changes in both the files.

session1.php:
<?php
$session['id']=session_id();
$_SESSION['username']=$userid;
?>

welcome.php:
<?php
error_reporting(E_ALL);
echo "The variable stored in the session is ".$_SESSION['username'];
?>

Now this is working fine. But my trouble comes now.

The functionality of my application is:
When User Logins, the UserName will be saved as session variable.
After his successful Login, a welcome page is displayed.
Here he can choose an option i.e.
View Alumni Directory
Update Account Information
Contact Us

Now if User select Update account Info, the UpdateAccount.php page is displayed. When User enter the Info and Click "Update Button" the control is transferred to UpdateAccountck.php page where database connectivity is done.Then a MySql query is executed:

The code for this page is:
UpdateAccountck.php:

<?php>
error_reporting(E_ALL);
echo "The variable stored in the session is ".$_SESSION['username'];
$user = $_SESSION['username'];

$str = "UPDATE Users SET firstname = '$firstname',middlename = '$middlename',lastname = '$lastname'," .
" address = '$address', emailaddress = '$email',phoneno = '$phone',year = '$batchyear' where username = $user";
mysql_query($str,$link);
?>

Here the error comes is:
Notice: Undefined variable: _SESSION in c:\inetpub\wwwroot\SchoolAlumniWebsite\Project files\UpdateAccountck.php on line 132
The variable stored in the session is
Notice: Undefined variable: _SESSION in c:\inetpub\wwwroot\SchoolAlumniWebsite\Project files\UpdateAccountck.php on line 133

When User Logins, newSession.php is called.
The code for newSession.php is same
newsession.php:
<?php
$_SESSION['id']=session_id();
$_SESSION['username']=$user;
?>

Please reply me.

opelit
11-03-2006, 10:21 AM
Hi!
I myself got the solution for this trouble.
For every php page i have to start a session at first. i.e.
session_start()
So now i can access the session variable on any page by
echo $_SESSION['username'];

opelit

Troy297
11-03-2006, 10:45 PM
Well... my interpretation would be to change your original Source #1 to:


<?php
session_start();
session_register("session");
$id=session_id();
$username=$userid;
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum