please help me with this because whenever i open this i am getting the same error.In my database i inserted an email and password but now when i insert the same into the login form i am getting that the email or password is incorrect even though they are correct which i had entered enter image description here
user.php
<?php
class User{
protected $pdo;
function __construct($pdo){
$this->pdo = $pdo;
}
public function checkInput($var){
$var = htmlspecialchars($var);
$var = trim($var);
$var = stripcslashes($var);
return $var;
}
public function login($email, $password){
$stmt = $this->pdo->prepare("SELECT 'user_id' FROM 'users' WHERE 'email' = :email AND 'password' = :password");
$stmt->bindParam(":email", $email, PDO::PARAM_STR);
$tempo = md5($password);
$stmt->bindParam(":password", $tempo, PDO::PARAM_STR);
$stmt->execute();
$user = $stmt->fetch(PDO::FETCH_OBJ);
$count = $stmt->rowCount();
if($count > 0){
$_SESSION['user_id'] = $user->user_id;
header('Location: home.php');
}else{
return false;
}
}
}
?>
login.php
<?php
if(isset($_POST['login']) && !empty($_POST['login'])){
$email =$_POST['email'];
$password =$_POST['password'];
if(!empty($email) && !empty($password)){
$email = $getFromU->checkInput($email);
$password = $getFromU->checkInput($password);
if(!filter_var($email , FILTER_VALIDATE_EMAIL)){
$error = "Invalid format";
}else{
if($getFromU->login($email, $password)==false){
$error = "The email or password is incorrect!";
}
}
}else{
$error = "Please enter username and password!";
}
}
?>
<div class="login-div">
<form method="post">
<ul>
<li>
<input type="text" name="email" placeholder="Please enter your Email here"/>
</li>
<li>
<input type="password" name="password" placeholder="password"/><input type="submit" name="login" value="Log in"/>
</li>
<li>
<input type="checkbox" Value="Remember me">Remember me
</li>
<?php
if(isset($error)){
echo ' <li class="error-li">
<div class="span-fp-error">'.$error.'</div>
</li>';
}
?>
</ul>
</form>
</div>