Hello,
How do I solve the problem of when someone edit the profile on mobile and at the same time is logged on the pc, do not give php error as 'Undefined variable' in the pc because the data are no longer the same as the mobile ..
For example, the login is william ai I logged in the cell phone and the pc, then I edited my cell phone login to curruwilla and I saved it, there on the pc it is like william still giving error
Here is a session to retrieve user data: How can I improve this to select users by ID for when I do not change the username or password do 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's your 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;
}
}