In my login page. when username or password is incorrect then it is displays both if condition statements and also display this error: "Trying to access array offset on value of type null".kindly help me out to figure this out. thanks in advance.
Here is the code:
if(isset($_POST['login']))
{
$username=$_POST['username'];
$password=$_POST['password'];
$sql="select * from users where user_name='".$username."' and password='".$password."' ";
$result=mysqli_query($con,$sql);
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
if (mysqli_num_rows($result) === 1)
{
echo '<script>alert("Login successfully")</script>';
}
else
{
if($row["user_name"] != $_POST['username'])
{
echo "username is incorrect";
}
if($row["password"] != $_POST['password'])
{
echo "password is incorrect";
}
}
}
and here is the error:
Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\selfstudy\login.php on line 75
username is incorrect
Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\selfstudy\login.php on line 79
password is incorrect