My login page seems to redirect me to index.php with any login field inputs. This is unexpected as it's supposed to perform checks. Also, if the login fields are left blank, it redirects to a blank page. This also should not be so as I have set up a condition to deal with this result. See
logininc.php
<?php
require_once("assets/configs/db_config.php");
$user=$_POST['user'];
$password=$_POST['password'];
if(isset($_POST['submit'])){
//To ensure that none of the fields are blank when submitting the form if
if($user != NULL || $password != NULL)
// if(isset($_POST['user']) && isset($_POST['password'])) old code
{
$user = stripslashes($user);
$password = stripslashes($password);
$user = mysqli_real_escape_string($user);
$password = mysqli_real_escape_string($password);
$sql="SELECT * FROM $test_db WHERE user='$user' and password='$password'";
$result=mysqli_query($sql);
$row=mysqli_fetch_array($result);
if($row['user'] == $user && $row['password'] == $password)
{
session_start();
$_SESSION['user'] = $user;
$_SESSION['password'] = $password;
$_SESSION['loggedin'] = "true";
header("location:index.php");
}
else
{
echo ('<div id="error">Computer says no.</div>');
}
echo ('<div id="error">Enter something!</div>');
}
}
login.php
<form id="login-form" method="post" action="logininc.php"> <fieldset>
<legend>Login </legend>
<p>Please enter your username and password to access the administrator's panel</p>
<label for="user"> <input type="text" name="user" placeholder="Type your username here" id="user" /></label>
<label for="password"> <input type="password" name="password" placeholder="Type your password here" id="password" /></label>
<label for="submit"> <input type="submit" class="btn btn-primary"name="submit" id="submit" value="Login" /> </label> </fieldset> </form>
Please advise.