i have a login form that transmit the information to the php code in the same page but even the username and password are correct it always ignore him this is my php code:
$mail = test_input($_POST["email"]);
//check if the email address format is valid
if (!filter_var($mail, FILTER_VALIDATE_EMAIL)) {
echo "<h3>Invalid email format</h3>";
}
$pass = trim($_POST["password"]);
$stmtn="SELECT first_name, email , password FROM `users` WHERE email= '$mail'";
$result = mysqli_query($connection,$stmtn);
$rows= mysqli_fetch_assoc($result);
if($rows && $rows['password']== md5($pass)){
session_start();
$_SESSION['username']=$rows['first_name'];
header("Location: index.php");
}else{
echo "<h3> Sorry! your email or password is incorrect </h3>";
echo "<h3> Please <strong><a href='login.php'>login</a></strong> again to your account </h3>";
echo var_dump($rows);
}
the statements in the else part always are executed and the result of the var_dump for the array $rows is equal to the information in the db exactly
and this is the code of the function test_input
<?php
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}