Answer the question
In order to leave comments, you need to log in
Why can't I log in?
Why can't I log in? The code seems to be correct but does not authorize!
I get an errorWoops! Email and Password cannot be empty...
<?php
session_start();
include "config.php";
if (isset($_POST["login"])) {
if($_POST["username"]=="" or $_POST["email"]=="" or $_POST["password"]=="") {
echo "<script>alert('Woops! Email and Password cannot be empty...')</script>";
} else{
$email = trim($_POST["email"]);
$username = strip_tags(trim($_POST["username"]));
$password = strip_tags(trim($_POST["password"]));
$query=$db->prepare("SELECT * FROM users WHERE email=? AND password=?");
$query->execute(array($email, $password));
$control=$query->fetch(PDO::FETCH_OBJ);
if($control>0) {
$_SESSION["username"]=$username;
header("Location:dashboard.php");
}
echo "<script>alert('Woops! Email or Password is Wrong.')</script>";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="style.css">
<title>Login Form - Pure Coding</title>
</head>
<body>
<div class="container">
<form action="" method="POST" class="login-email">
<p class="login-text" style="font-size: 2rem; font-weight: 800;">Login</p>
<div class="input-group">
<input type="text" placeholder="Username" name="password">
</div>
<div class="input-group">
<input type="email" placeholder="Email" name="email">
</div>
<div class="input-group">
<input type="password" placeholder="Password" name="password">
</div>
<div class="input-group">
<button type="submit" name="login" class="btn">Login</button>
</div>
</form>
</div>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question