i have a login page and it works well. but how can i make like after the log in successfully and all my other pages will have Welcome (lastname) of the user ?
as currently, after log in succesfully will redirect to welcome.php and it seems like it only able to get the email only instead of lastname. and what the correct way to display eg welcome John in all pages.
thanks
login script
<?php
// Array for recording errors:
$login_errors = array();
// Validate the email address:
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$e = mysqli_real_escape_string ($dbc, $_POST['email']);
} else {
$login_errors['email'] = 'Please enter a valid email address!';
}
// Validate the password:
if (!empty($_POST['pass'])) {
$p = mysqli_real_escape_string ($dbc, $_POST['pass']);
} else {
$login_errors['pass'] = 'Please enter your password!';
}
if (empty($login_errors)) { // OK to proceed!
// Query the database:
// $q = "SELECT email, password FROM members1 WHERE (email='$e' AND password='$p')";
$q = "SELECT userid, email, firstname, lastname, password FROM members2 WHERE (email='$e' AND password='$p')";
$q2 = "SELECT admin FROM members2 WHERE (admin='1')";
$r = mysqli_query ($dbc, $q);
//$objQuery = mysql_query($q) or die ("Error Query [".$q."]");
//$r2 = mysqli_query ($dbc, $q2);
if (mysqli_num_rows($r) == 1) { // A match was made.
// Get the data:
//header('Location: welcome.php');
$welcomepage = "welcome.php";
echo '<script language="javascript" type="text/javascript">window.location.href="'.$welcomepage.'";</script>';
$row = mysqli_fetch_array ($r, MYSQLI_NUM);
$_SESSION['email'] = $_POST['email'];
}
else { // No match was made.
$login_errors['login'] = 'The email address and password do not match those on file.';
}
} // End of $login_errors IF.
welcome.php note: part of the code only. (intend to save it as header.php and include it in all other pages)
<div class="mainbar">
<div class="mainbar_content"> <img class="loginlogo_s" src="styles/Images/loginlogo_s.png" alt="loginlogo" />
<div class="login"><a href="login-register-page.php" >Logout</a></div>
<div class="createbar"></div>
<img class="create_s" src="styles/Images/create_s.png" alt="creates"/>
<div class="create"><a href="login-register-page.php" >Welcome</a><span class="style2"><?php echo $_SESSION["email"]; ?> </span></div>
</div>
</div>