Error performing a filter with SQL

0

I can not identify the error that is occurring in the code below:

$bannerguia=mysqli_query($con,"SELECT id, senha FROM conta WHERE senha = '$senhalog'");
while($painel_banner=mysqli_fetch_array($bannerguia))
{
     $issenha = $painel_banner['senha'];
     $isid = $painel_banner['id'];
}

In SQL when I put the variable $senhalog in quotation marks '$senhalog' the filter does not work, if it does not put quotation marks it works, but it gives error if it does not find anything.

In all the systems I develop I put quotation marks around and everything works perfectly, I did not understand what's happening here.

    
asked by anonymous 28.03.2018 / 23:49

2 answers

1

Think of me, you said "if it does not find anything without quotation marks gives error" , if I understood the not find anything would be $senhalog ? If yes, it will give an error because the generated select will be:

SELECT id, senha FROM conta WHERE senha =

and this gives error in any bank.

If the password is type string it will need quotes if it does not make an if ternary in the variable saying that if it has value it does not put something like null (it does not make sense that $ senhalog does not exist).

    
29.03.2018 / 00:05
1

Put your queries into variables in this way you will have more control over the result.

<?php
    $sql = "SELECT id, senha FROM conta WHERE senha ='".$senhalog."';";
    //echo $sql;
    $bannerguia=mysqli_query($con,$sql);
    while($painel_banner=mysqli_fetch_array($bannerguia))
    {
         $issenha = $painel_banner['senha'];
         $isid = $painel_banner['id'];
    }
?>
    
29.03.2018 / 00:16