Good afternoon, I was trying to study a registration system using session in php the part of the registry works normal, the problem is at the time of logging, even with the correct password I get the following 2 errors:
Notice: Undefined variable: query in C:\wamp64\www\Login\Logar.php on line 30 Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in C:\wamp64\www\Login\Logar.php on line 30
Here is the relevant snippet of code:
<?php
if(isset($_POST["submit"])){
if(!empty($_POST['user']) && !empty($_POST['pass'])){
$user = $_POST['user'];
$pass = $_POST['pass'];
$conn = new mysqli('localhost', 'root', 'admin') or die (mysqli_error());
$db = mysqli_select_db($conn, 'login') or die("databse error");
$query = mysqli_select_db($conn, "SELECT * FROM login WHERE user= '".$user."' AND pass='".$pass."'");
linha 31 >>> $numrows = mysqli_num_rows($query);
if($numrows !=0)
{
while($row = mysqli_fetch_assoc($query))
{
$dbusername=$row['user'];
$dbpassword=$row['pass'];
}
if($user == $dbusername && $pass == $dbpassword)
{
session_start();
$_SESSION['sess_user']=$user;
//Redirect Browser
header("Location:welcome.php");
}
}
else
{
echo "Invalid Username or Password!";
}
}
else
{
echo "Required All fields!";
}
}
?>
Every time I try to log in even though the information is correct I get the following error
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\wamp64\www\Login\Logar.php on line 31