I'm struggling with finding why I can't log in, I created my user in the MySQL database with md5 encryption on the password and also set that correctly up in the database, here is my code. It comes up with an invalid username or password but I'm 100% sure that I have added it correctly in the MySQL
users.php, i think my problem might be in here, but i just cant find it
<?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);
//ORIGINAL
//OLD CODE $stmt->bindParam(":password", md5($password), PDO::PARAM_STR);
$password = md5($_POST['password'], PDO::PARAM_STR);
$stmt->bindParam(':password',$password);
//END OF ORIGINAL
$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;
}
}
}
?>
My login.php
<?php
if(isset($_POST['login']) && !empty($_POST['login'])){
$email = $_POST['email'];
$password = $_POST['password'];
if(!empty($email) or !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>