problematic mysql query

Asked

Viewed 135 times

-4

have the following data
admlogin: admin1 admpassword:admin
admlogin: admin2 admpassword:admin
admlogin: admin3 admpassword:admin

  <form action="#" method="post" id="frm_login_p" name="frm_login_p">
    <input class="form-control" type="text" name="p_login" placeholder="Login, CNPJ ou Telefones" id="p_login">
    <input class="form-control" type="password" name="p_senha" required="" placeholder="Senha" maxlength="255" minlength="2" id="p_senha">
  </form>


<?php 
$atividade='1';
$login=$_POST['p_login'];
$senha=$_POST['p_senha'];
$sql="SELECT id,nome,cnpj FROM  tbl_postos WHERE cnpj='".$login."' AND admsenha='".$senha."' AND ativo='".$atividade."' OR telefone='".$login."' AND admsenha='".$senha."' AND ativo='".$atividade."' OR whatsapp='".$login."' AND admsenha='".$senha."' AND ativo='".$atividade."' OR email='".$email."' AND admsenha='".$senha."' AND ativo='".$atividade."' OR admlogin='".$login."' AND admsenha='".$senha."' AND ativo='".$atividade."'"; 

        if ($result = @mysqli_query($CnHUP,$sql)){
        while($row = @mysqli_fetch_array($result)) {
        $ident=$row['id'];
        $cnpj=$row['cnpj'];
        $nome=$row['nome'];
        echo "Identificador: $ident CNPJ: $cnpj Nome: $nome";
        }}
    ?>

at least in theory, only admlogin/admin found in the table should be displayed; the problem is that when finding a smaller value...
for example: Adm or Admi or admin... it keeps selecting and displaying the information. how to select only the exact value ? admin1 or admin2 or admin3

1 answer

0


SOLUTION WAS TO AMEND THE CONSULTATION

$sql="SELECT id,nome,cnpj FROM  tbl_postos WHERE cnpj='".$login."' AND admsenha='".$senha."' AND ativo='".$atividade."' OR telefone='".$login."' AND admsenha='".$senha."' AND ativo='".$atividade."' OR whatsapp='".$login."' AND admsenha='".$senha."' AND ativo='".$atividade."' OR email='".$email."' AND admsenha='".$senha."' AND ativo='".$atividade."' OR admlogin='".$login."' AND admsenha='".$senha."' AND ativo='".$atividade."'"; 

FOR

$sql="SELECT id,nome,cnpj FROM  tbl_postos  WHERE cnpj in ('".$login."') AND admsenha in ('".$senha."') AND ativo in ('".$atividade."') OR telefone in ('".$login."') AND admsenha in ('".$senha."') AND ativo in ('".$atividade."') OR whatsappin in ('".$login."') AND admsenha in ('".$senha."') AND ativoin ('".$atividade."') OR email in ('".$email."') AND admsenha in ('".$senha."') AND ativo in ('".$atividade."') OR admlogin in ('".$login."') AND admsenha in ('".$senha."') AND ativo in ('".$atividade."')";

Browser other questions tagged

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