Login with validation does not work

Asked

Viewed 31 times

-1

There is a login that I use for all systems that I develop and works on all of them, except in this case.

Login.php

<!-- Formulário -->

<form method="post" action="validacao.php">
    <div class="form-group col-lg-4" style="padding-left: 0px;">
        <input type="text" class="form-control" id="id" name="id" placeholder="Insira seu id" requiered>
    </div>
    <div class="form-group col-lg-4" style="padding-left: 0px;">
        <input type="password" class="form-control footer-input margin-b-20" name="senha" placeholder="Insira sua senha" required>
    </div>
    <button type="submit" class="btn-theme btn-theme-sm btn-white-brd text-uppercase">Entrar</button>
</form>

Validation.php

<?php
//Esse login ficou meio complicadinho, então vou deixar comentado: 
ini_set('display_errors', true);
error_reporting(E_ALL);
// Primeiro verifica se o post não está vazio
if (!empty($_POST) AND !empty($_POST['ID']) OR !empty($_POST['SENHA'])) {
    $link = mysql_connect('localhost', 'root', '');
    mysql_select_db('banco');
    // Tenta se conectar a um banco de dados MySQL
    $id = mysql_real_escape_string($_POST['ID']);
    $senha = mysql_real_escape_string($_POST['SENHA']);
    $ativo = mysql_real_escape_string($_POST['ATIVO']);
    //$senha = md5($senha);

    $sql = "SELECT `ID`, `ID`, `SENHA`, `ATIVO`  FROM `usuarios` WHERE (`ID` = '". $id ."') 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: about.html"); } 
      else { header("Location: contact.html"); }

      exit;
    }
}
?>

When I soon go to the validation page and stay there without redirecting or to about html. nor to contact.html

I can’t see the problem, someone knows what might be going on?

1 answer

1


Taking out the bank credentials, I believe it’s Case Sensitive’s problem. Try it the way below:

<?php
ini_set('display_errors', true);
error_reporting(E_ALL);

if (!empty($_POST) && !empty($_POST['id']) && !empty($_POST['senha'])) {
    $link = mysql_connect('localhost', 'root', '');
    mysql_select_db('banco');
    // Tenta se conectar a um banco de dados MySQL
    $id = mysql_real_escape_string($_POST['id']);
    $senha = mysql_real_escape_string($_POST['senha']);
    $ativo = mysql_real_escape_string($_POST['ativo']);
    //$senha = md5($senha);

    $sql = "SELECT `id`, `senha`, `ativo`  FROM `usuarios` WHERE `id` = '". $id ."' && `senha` = '". $senha ."'";
    $query = mysql_query($sql);
    if (mysql_num_rows($query) != 1) {

      echo "Login inválido!"; exit;
    } else {
      $resultado = mysql_fetch_assoc($query);

      if ($resultado['ativo'] == 0) { header("Location: about.html"); } 
      else { header("Location: contact.html"); }

      exit;
    }
}
  • It’s weird that it’s because I always do the whole table using the caps. But strangely it worked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.