In the login of my system, if the user has id and password registered the access is released. So far so good, but now I want to qualify this user in administrator (1) or simple user (0) so that when they log in, they are redirected to different pages.
For this, I created a "ativo"
column to store the 0 or 1 in my user table and started writing a validation page that is not yet working:
<?php
// Primeiro verifica se o post não está vazio
if (!empty($_POST) AND !empty($_POST['identifiant']) OR !empty($_POST['senha'])) {
mysql_connect('localhost', 'root', '', 'db_formacao') or trigger_error(mysql_error());
// Tenta se conectar a um banco de dados MySQL
$identifiant = mysql_real_escape_string($_POST['identifiant']);
$senha = mysql_real_escape_string($_POST['senha']);
$ativo = mysql_real_escape_string($_POST['ativo']);
$sql = "SELECT 'id', 'identifiant', 'senha', 'ativo' FROM 'usuarios' WHERE ('identifiant' = '". $identifiant ."') AND ('senha' = '". $senha ."')";
$query = mysql_query($sql);
if (mysql_num_rows($query) != 1) {
// Mensagem de erro quando os dados são inválidos e/ou o usuário não foi encontrado
echo "Login inválido!"; exit;
} else {
$resultado = mysql_fetch_assoc($query);
// Verifica se o usuário é 0 ou 1
if ($resultado['ativo'] == 0)) { header("Location: principalUSU.php"); }
else { header("Location: principal.php"); }
exit;
}
}
?>
The login page is where the form responsible for the login is and the action that links to the validation page:
<!--CONTENT-->
<!--A parte do formulário-->
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="login-panel panel panel-default">
<div class="panel-heading" style="
margin-top: 14px;">
<h3 class="panel-title">Login</h3>
</div>
<div class="panel-body" style="background: rgba(32, 40, 76, 0.59);">
<?php
if(isset($erro))
if(count($erro) > 0){ ?>
<div class="alert alert-danger">
<?php foreach($erro as $msg) echo "$msg <br>"; ?>
</div>
<?php
}
?>
<form method="post" action="validacao.php" role="form">
<fieldset style="background: #9498a9;">
<div class="form-group">
<input class="form-control" placeholder="Identifiant" name="identifiant">
</div>
<div class="form-group">
<input class="form-control" required placeholder="Senha" name="senha" type="password" value="">
</div>
<div class="checkbox">
<label>
<input name="remember" type="checkbox" value="Remember Me">Lembrar-me
</label>
</div>
<button type="submit" name="login" value="true" class="btn btn-success btn-block" style="background: #232b4f; border-color: #e2e2e2;">Login</button>
</fieldset>
</form>
</div>
</div>
</div>
</div>
</div>
The table as in the database:
id | nome | senha | ativo
1 aaaa 12345 1
2 bbbb 12345 0
But when I try to run the page, it appears that erro 500
saying that the page is not working.
Any idea why it does not work?
obs: I changed my code to what appears here in the answer, but it is still giving 500 error.