I have a system with a required login.
What should happen: If the "active" column is = 1 redirects to a certain page, if it is = 0 redirects to another page.
<?php
if (!empty($_POST) AND (empty($_POST['id']) OR empty($_POST['senha']) AND ('ativo' = 1)) {
header("Location: principal.php"); exit;
} else {
if (!empty($_POST) AND (empty($_POST['id']) OR empty($_POST['senha']) AND ('ativo' = 0){
header("Location: principalUSU.php"); exit;
}
}
mysql_connect('localhost', 'root', '', 'db_formacao') or trigger_error(mysql_error());
$identifiant = mysql_real_escape_string($_POST['id']);
$senha = mysql_real_escape_string($_POST['senha']);
$ativo = mysql_real_escape_string($_POST['ativo']);
$sql = "SELECT 'id', 'id', 'senha', 'ativo' FROM 'usuarios' WHERE ('id' = '". $id ."') AND ('senha' = '". $senha ."') AND ('ativo' = '". $ativo ."')";
$query = mysql_query($sql);
if (mysql_num_rows($query) != 1) {
echo "Login inválido!"; exit;
} else {
$resultado = mysql_fetch_assoc($query);
}
Only on both occasions it redirects to page principal.php
.