I have designed the login page as shown below with the functionality to check from the database. I want the site to redirect the user to their specified page displaying their reports page (view_report.php) after successful login. For some reason, after entering the details, the page returns back to the same page instead of not logging in and doesn't throw any errors as well. I'm not sure as to where I went wrong. Thanks for the help in advance. :-)
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
----header area----
</head>
<body>
<div class="logo"></div>
<div class="login"> <!-- Login -->
<h1>Login</h1>
<form class="form" method="POST" action="index.php">
<p class="field">
<input type="text" name="login" placeholder="Restaurant id" required/>
<i class="fa fa-user"></i>
</p>
<p class="field">
<input type="password" name="password" placeholder="Password" required/>
<i class="fa fa-lock"></i>
</p>
<p class="submit"><input type="submit" name="commit" value="Login"></p>
<p class="remember">
<input type="checkbox" id="remember" name="remember" />
<label for="remember"><span></span>Remember Me</label>
</p>
<p class="forgot">
<a href="#">Forgot Password?</a>
</p>
</form>
</div> <!--/ Login-->
<?php
if( $_SESSION["logging"]&& $_SESSION["logged"])
{
header("Location:view_report.php");
}
else {
if(!$_SESSION["logging"])
{
$_SESSION["logging"]=true;
}
else if($_SESSION["logging"])
{
$number_of_rows=checkpass();
if($number_of_rows>=1)
{
$_SESSION[user]=$_GET[userlogin];
$_SESSION['logged']=true;
header("Location:view_report.php");
}
}
}
function checkpass()
{
$servername="localhost";
$username="root";
$conn= mysql_connect($servername,$username)or die(mysql_error());
mysql_select_db("konjam_disc",$conn);
$sql="select * from users where name='$_GET[userlogin]' and password='$_GET[password]'";
$result=mysql_query($sql,$conn) or die(mysql_error());
return mysql_num_rows($result);
}
?>
</body>
</html>