Unknown column '' in 'Where clause'. Error mysql php

Asked

Viewed 426 times

-2

Below is the code I am using to try to make a login system, but it is failing

Code:

<?php
   
$link = mysqli_query($con, "SELECT * FROM usuarios WHERE nome= $nome AND senha = $senha") or die(mysqli_error($con));
    
    
    if(mysqli_num_rows($link) <= 0)
    {
        header("Location:../inicio.php");
    }else
    {
        echo
        "
        <script type='text/javascript'>
            alert('nome de usuário e/ou senha incorretos');
            window.location.href='../index.php';
        </script>
        ";
    }

?>


Similar message: Unknown column 'teste_bot' in 'Where clause'

Note 1 - I have directly entered a user with name and password in the database called 'teste_bot'

Note 2 - if I put '$name' and '$password' gets the following error -Recoverable fatal error: Object of class mysqli_result could not be converted to string in /Storage/ssd1/516/14288516/public_html/SQL/logar.php on line 10

  • The fields $nome and $passwordnão deveria estar entre apóstrofos?'$name'e'$password'`.

  • If I put this error

1 answer

-1

First, how is saved this field of name and password in your bank?

second, put $name and $password in single quotes '$name' '$password' is the default to work

third, fix this if(mysqli_num_rows($link) <= 0
thus the validation is wrong, because it does not make sense the number of results to be <= 0 and it takes you to the start page the right one is if(mysqli_num_rows($link) >= 1 or, invert the orders, if the query returns <= 0 put the Alert alert('incorrect username and/or password'); and on Else send it to the logged in page

corrected code:

$link = mysqli_query($con, "SELECT * FROM usuarios WHERE nome = '$nome' AND senha = '$senha'") or die(mysqli_error($con));

  if(mysqli_num_rows($link) >= 1){
    //loga o usuário
  }else{
    //erro ao logar
  }

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

Browser other questions tagged

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