I'm creating a website with sign up/login capabilities and wanting the page to display the user's name after logging in through multiple elements of the site. There are three main sections for getting the client information, the sign in page (just a post method form), the verification page which verifies the password and email on the database, and also sets the session variable, then the welcome back page which should echo the name, but only echo's the value "0".
The verification script is:
<?PHP
//Start a session
session_start();
//Connect to the database
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("PhoneBro") or die(mysqli_error());
//Assign varibales to input data
$email = $_POST['email'];
$password = md5($_POST['password']);
//Query database to check information
$query = mysql_query("SELECT * FROM Customers WHERE Email='$email' AND Password='$password'") or die();
//Remember information about user to use later
$_SESSION['name'] = mysql_query("SELECT FirstName FROM Customers WHERE Email='$email'") or die();
//Validate login or redirtect if incorrect
if (mysql_num_rows($query)>0){
header('location: loginSuccess.php');
exit();
}else{
header('location: loginFail.php');
exit();
};
?>
And the code for the welcome page:
<?PHP
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>PhoneBro | Welcome Back</title>
</head>
<body>
<div class="center">
<p>Welcome back,
<?PHP
echo $_SESSION['name']; ?>
</p>
<a href="signOut.php">
<button>Sign Out</button>
</a>
</div>
</body>
</html>
The spelling in the query is correct to the database and as it was successfully able to verify the username and password, I can't imagine why it wouldn't return any values for the FirstName query either. Please ask if more information is needed.