Fatal error in login system

0

I'm doing a login system in PHP and resulted in a fatal error:

  

Fatal error: Call a member function num_rows () on a non-object in   C: \ xampp \ htdocs \ avulso-2 \ valid-user.php on line 10

    <?php
      $conecta = new mysqli("localhost", "root", "", "avulso");

      $login = $conecta->real_escape_string($_POST['login']);
      $senha = $conecta->real_escape_string($_POST['senha']);

      $sql_usuario = "SELECT id, nome, login, senha FROM usuario WHERE login = " .$login. " AND senha = " .$senha. "LIMIT 1";
     $query_usuario = $conecta->query($sql_usuario);

     if($query_usuario->num_rows() != 1){ /* Nesta linha que ocorreu o erro: "Fatal error: Call to a member function num_rows() on a non-object in 
C:\xampp\htdocs\avulso-2\valida-usuario.php on line 10" */

    echo "Login inválido ou inexistente!";
     }
     else{
         $rs_usuario = $query_usuario->fetch_assoc();

         if(!isset($_SESSION)){
         session_star();
         $_SESSION['id'] = $rs_usuario['id'];
         $_SESSION['nome'] = $rs_usuario['nome'];

         header("Location: index.php"); exit;
      }

     }
   ?>
    
asked by anonymous 01.06.2015 / 01:19

1 answer

0

Text-type values must be enclosed in single quotation marks in your query, as in the code below. num_rows is a property and not a method so you do not need parentheses.

$sql_usuario = "SELECT id, nome, login, senha FROM usuario WHERE login = '" .$login. "' AND senha = '" .$senha. "' LIMIT 1";
 $query_usuario = $conecta->query($sql_usuario);

 if($query_usuario->num_rows != 1){
    
01.06.2015 / 01:30