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;
}
}
?>