2
Good afternoon guys, I was trying to study a registration system using Session in php the part of the registration works normal, the problem is time to log in, even with the correct password I get the 2 following 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 excerpt from the 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 even the information being 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
yes yes, that’s right buddy, thank you.
– John Jones