I am building a new project right now and finished my login/registration script. It is working so far but now I need a new function and I am not sure how exactly I should do that.
If a user logged in with success the first page the user will see is his profile. On this page I get my data with the following query:
<?php
session_start();
if(empty($_SESSION)) // if the session not yet started
session_start();
if(!isset($_SESSION['email'])) { //if not yet logged in
header("Location: login.php");// send to login page
exit;
}
include 'header.php';
$get = "SELECT * FROM user" or die(mysql_error());
$result_get = mysqli_query($connect, $get);
$_SESSION['data'] = mysqli_fetch_assoc($result_get);
?>
And inside my HTML code I get the data with the following code:
Firstname: <?php echo $_SESSION['data']['firstname']; ?>
Lastname: <?php echo $_SESSION['data']['lastname']; ?>
Username <?php echo $_SESSION['data']['username']; ?>
Problem is now, that I need to show the data only from the user which is currently logged in. Right now my query is "SELECT * FROM user" but I think I can change this query to something, that only the data are received from the currently logged in user. Something like "SELECT * FROM user WHERE SESSION"?!
I am not sure how I can achieve that.