I am trying to create a login form with PHP but it cannot login. I get incorrect password/username instead. I have triple checked the credentials in the database and they are correct. Please help
Here is the code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Login</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<?php
require('db.php');
session_start();
// If form submitted, insert values into the database.
if (isset($_POST['username'])){
$username = $_POST['username'];
$password = $_POST['password'];
$username = stripslashes($username);
$username = mysqli_real_escape_string($connection,$username);
$password = stripslashes($password);
$password = mysqli_real_escape_string($connection,$password);
//Checking is user existing in the database or not
$query = "SELECT * FROM `backuser` WHERE username='".$username."' and password='".md5($password)."'";
$result = $connection->query($query) or die(mysqli_error());
$rows = mysqli_num_rows($result);
if($rows==0){
$_SESSION['username'] = $username;
header("Location: index.php"); // Redirect user to index.php
}else{
echo " <div class='form'><h3>Username/password is incorrect.</h3><br/>Click here to <a href='login.php'>Login</a></div>";
}
}else{
?>
<div class="form">
<h1>Log In</h1>
<form action="" method="post" name="login">
<input type="text" name="username" placeholder="Username" required />
<input type="password" name="password" placeholder="Password" required />
<input name="submit" type="submit" value="Login" />
</form>
</div>
<?php } ?>
</body>
</html>