Statement
I would like to do a simple login validation where the condition is the username and password match to a table in MySQL server called admin
What I have tried so far
From the following code, there are undefined indexes in login_check.php
$uname = mysqli_real_escape_string($conn,$_POST['username'] );
and $pass = mysqli_real_escape_string($conn,$_POST['password'] );
login.php (front.php = main page)
<form method="post" action="login_check.php">
<input type="text" name="username" placeholder="Username" required>
<span class="error"><?php echo $uname_error; ?></span>
<input type="password" name="password" placeholder="Password" required>
<span class="error"><?php echo $pass_error; ?></span>
<button type="submit" name="Log In" value="Log In">Log In</button> <!--Go to front.php if both username and password are correct.-->
</form>
login_check.php
<?php
//Establish connection
include 'connection.php';
$uname_error = $pass_error ="";
$uname = mysqli_real_escape_string($conn,$_POST['username'] );
$pass = mysqli_real_escape_string($conn,$_POST['password'] );
$sql = "SELECT admin_username,admin_password FROM admins";
if(isset($_POST['Log In']))
{
//Check Username
if($uname == "username")
{
//Check Password
if($pass == "password")
{
header("location:front.php"); //If username & password are correct -> log in to front.php.
}
else //$pass != "password"
{
$pass_error = "Invalid Password.";
}
}
else //$uname != "username"
{
$uname_error = "Invalid Username.";
}
}
mysqli_close($conn);
?>
EDIT 1 : login.php has been fixed.
front.php, notlogin_check.phpyou includelogin_check.phpbefore the form has been posted so those values wont be set. you need to reaccesses the structure here