0
I need to make a query if the user is active. Ex.
I client log in to the panel, if my status is disabled, shows me a message, if my status is active log in to the page.
follows my code
<?php
// inclui o arquivo de inicialização
include_once('assets/conn/init.php');
// resgata variáveis do formulário
$email = isset($_POST['email']) ? $_POST['email'] : '';
$password = isset($_POST['senha']) ? $_POST['senha'] : '';
// cria o hash da senha
$passwordHash = make_hash($password);
$PDO = db_connect();
$sql = "SELECT * FROM usuarios WHERE email = :email AND senha = :password";
$stmt = $PDO->prepare($sql);
$stmt->bindParam(':email', $email);
$stmt->bindParam(':password', $passwordHash);
$stmt->execute();
$users = $stmt->fetchAll(PDO::FETCH_OBJ);
//Se o email não existir na base de dados gera um alerta
if (count($users) <= 0):
header('Location: index.php?msg=1');
exit;
endif;
// pega o primeiro usuário
$user = $users[0];
session_start();
$_SESSION['logged_in'] = true;
$_SESSION['user_id'] = $user['usuario_id'];
$_SESSION['nome'] = $user['nome'];
$_SESSION['email'] = $user['email'];
$_SESSION['nivel_usuario'] = $user['nivel_usuario'];
header('Location: home.php');
One solution is to insert into your table
usuários
a fieldstatus
where for example the value 1 would set an active user and 0, inactive. When playing all users of the query in the arrayusers
, you can check the field valuestatus
, depending on this, you show the inactive alert, if you are.– Simão Ítalo
In the database I already have this column that is called "active", as I do this application in my code?
– Betinho Silva