1
I have a system with login required.
What should happen: If the "active" column is = 1 redirects to a given page, if = 0 redirects to another.
<?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 the page principal.php
.
I believe there is some error in the verification of
$_POST
. To solve this I would try to give oneprint_r($_POST)
after the form is submitted to see what I’m getting in this array and try to find the error.– Leandro Lima
You’re checking to see if any string is one. I think the right one would be
_POST['ativo'] == 1
– Samuel Rizzon
I tried that, but it still redirects directly to the main.php
– Mariana Bayonetta