Reputation: 49
So I'm about to pass a variable at a second page. I tested the session at the top of my index page for me to know if session contains a variable. Like this:
<?php
error_reporting(E_ALL ^ E_NOTICE);
session_start();
$UserID = $_SESSION['CustNum'];
$UserN = $_SESSION['UserName'];
echo "$UserN";
?>
It's totally ok for the index page. It really prints the username. But when it comes to the next page where I'll pass the variable I tried the same code to see if the session contains something. But then, there's none. Help please. Also, these codes are both above my codes, above all else.
Upvotes: 0
Views: 1575
Reputation: 4325
According to your comment and code:
if($numrows === 1){ $row = mysql_fetch_assoc($query)or die ('Unable to run query:'.mysql_error());
// fetch associated: get function from a query for a database
$dbpass = $row['PassWord']; // read password of inputted user from the query.
$dbuser = $row['UserName']; // read username from the query
$dbactive = $row['Active']; // read if user is active $dbid = $row['CustNum'];
if($UserP == $dbpass){ if($dbactive == 1){ //set session information
$_SESSION['CustNum'] = $dbid;
$_SESSION['UserName'] = $dbuser;
}
..i suppose this: if($UserP == $dbpass){ if($dbactive == 1)
is false
. Check it.
Upvotes: 0
Reputation: 11
please try this method
in the first page
error_reporting(E_ALL ^ E_NOTICE);
session_start();
$_SESSION['CustNum']='12345';
$_SESSION['UserName']='sivanthi';
in the another page
error_reporting(E_ALL ^ E_NOTICE);
session_start();
echo $_SESSION['CustNum'];
echo $_SESSION['UserName'];
Upvotes: 0
Reputation: 1344
Do you declare a session_start()
on your other page ?
And you need to initialize $_SESSION['UserName']
somewhere.
Just like this $_SESSION['UserName'] = "my_username"
Upvotes: 0
Reputation: 4325
Where is:
$_SESSION['CustNum'] = 'xxx';
$_SESSION['UserName'] = 'yyy';
?
Upvotes: 3