0
Good Afternoon Guys, I am making a system for company where I work but I have a problem that I can not solve.
This is the Code I’m using:
Code to show user and position
require('conBanco.php'); #conexão com o Banco de Dados
if(isset($_POST['UsrEmail']) && isset($_POST['UsrSenha'])){ #Caso o usuário esteja logando
$queryUser1 = mysqli_query($mysqli, "SELECT * FROM usuarios WHERE UsrEmail = '$_POST[UsrEmail]' AND UsrSenha = '$_POST[UsrSenha]' LIMIT 1");
if(mysqli_num_rows($queryUser1) != 0){
if($queryUser = mysqli_fetch_assoc($queryUser1)){
$_SESSION['UserLogado'] = $queryUser['UsrID']; #Salva em uma variável de Sessão a ID do usuário que está logado
header('Location: login.php');
}else{
echo $LoginErro;
}
}else{
echo $LoginErro;
}
}else{ #Caso o usuário já esteja logado
$QueryLogado = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT UsrID, UsrNome, UsrSenha, UsrEmail, UsrNvl, NvlNome FROM usuarios INNER JOIN usuarionivel ON UsrNvl = NvlID;"));
echo "Bem vindo <b>".$QueryLogado['UsrNome']."</b>, tudo bem?<br>Não esqueça que você é <b>".$QueryLogado['NvlNome']."</b> nesta Empresa!";
echo '<br><a href=../config/Deslogar.php>Sair</a>';
}
The problem is this: I want to show the user his name and his position in the company however, whenever I log in with any different user, with different emails it only shows the name of the ADMINISTRATOR.
someone knows where I might be missing ?
A comment: Are you, at any time, initiating the session with the session_start() method? To store the data in the $_SESSION global, you must do this before. I ask this because when the user is logged in, which parameter do you use to recover it? Apparently none. Always return the same: the administrator.
– ndr458
I couldn’t quite understand the part of which parameter I’m using, and yes I’m starting the session on the page and capturing the data in the code above in the variable $queryuser.
– Rodrigo Araújo
In the situation where the user is already logged in, below the comment: "#If the user is already logged in", you do not pass any parameter to query that indicates which user should be returned, so the returned should always be the "Administrator". Add a parameter in the query to return the user according to the session.
– ndr458