-2
Hello,
How do I solve the problem when someone edit the profile on mobile and at the same time is logged in on the pc, do not give php error as 'Undefined variable' on the pc because the data is no longer the same as mobile..
For example, the login is William ai I logged in on mobile and pc, then I edited my login on mobile to curruwilla and saved, ai on pc is like William still giving error
Here ta as Session to retrieve user data: How can I improve this to select the users by ID for when I do not change the username or password does not give error ?
if(isset($_SESSION['useronnected']) && (isset($_SESSION['passconnected']))){
$userLogged = $_SESSION['useronnected'];
$passLogged = $_SESSION['passconnected'];
// seleciona o usuario logado
$selectLogged = "SELECT * from users WHERE user=:userLogged AND password=:passLogged";
try {
$result = $conexao->prepare($selectLogged);
$result->bindParam('userLogged', $userLogged, PDO::PARAM_STR);
$result->bindParam('passLogged', $passLogged, PDO::PARAM_STR);
$result->execute();
$count = $result->rowCount();
if($count =1){
$loop = $result->fetchAll();
foreach ($loop as $show) {
$idLogged = $show['id'];
$nameLogged = $show['name'];
$userLogged = $show['user'];
$passwordLogged = $show['password'];
$emailLogged = $show['email'];
$levelLogged = $show['level'];
}
}
}catch (PDOException $e){ echo $e;}
}
if(!isset($_SESSION['useronnected']) && (!isset($_SESSION['passconnected']))){
$levelLogged = 0;
}
And here is the login:
if(isset($_POST['loggin'])){
// RECUPERAR DADOS DO FORM
$user = trim(strip_tags($_POST['user']));
$password = trim(strip_tags($_POST['password']));
//SELECIONAR BANCO DE DADOS
$select = "SELECT * FROM users WHERE BINARY user=:user AND BINARY password=:password";
try {
$result = $conexao->prepare($select);
$result->bindParam(':user', $user, PDO::PARAM_STR);
$result->bindParam(':password', $password, PDO::PARAM_STR);
$result->execute();
$count = $result->rowCount();
if($count>0){
$user = $_POST['user'];
$password = $_POST['password'];
$_SESSION['useronnected'] = $user;
$_SESSION['passconnected'] = $password;
header("Location: page.php");
}else{
echo '<div class="alert alert-danger">
<strong>Erro ao logar!</strong> Os dados estão incorretos.
</div>';
}
}catch(PDOException $e){
echo $e;
}
}
Please avoid long discussions in the comments; your talk was moved to the chat
– Maniero