Not able to login with correct credentials

  database, mysql, php

I have made a simple login and signup page but when i try to login with correct credentials stored in my databse and redirect the page to the home page it shows invalid credentials .
Here is my php script oh login page.

<?php
ini_set('display_errors',0);
if($_SERVER["REQUEST_METHOD"]=="POST")
{
$login=false;

include 'partials/_dbconnect.php';
$username=$_POST["username"];
$password=$_POST["password"];

$check=mysqli_query($conn,"select * from fds_signup where username='$username'AND password ='$password' ");
$checkrows=mysqli_num_rows($check);

if($checkrows >0)
{
    $login=true;
    session_start();
    $_SESSION['loggedin']=true;
    $_SESSION['username']=$username;
    header("location: home.php");
}
else{
    echo '<div class="alert alert-warning alert-dismissible fade show" role="alert">
        <strong>Oops!</strong> Invalid Credentials 
        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
    </div>';
}
}
?>

and this is of the home page to which i want the login page to redirect after successfull login

<?php
session_start();
if(!isset($_SESSION['loggedin']) || $_SESSION['loggedin']!=true){
    header("location:login.php");
    exit;
}
?>

Source: Ask PHP

LEAVE A COMMENT