I have created a HTML login page, it has a user login form and a moderator login form, the user login is working fine, it connects to the database, retrieves the email and password then redirects the user back to the home page, I'm using basically the same code for the moderator login but it wont work.
Here are screenshots of my database http://i59.tinypic.com/91fcpj.png This is after the user logs in, it redirects to index.php http://i61.tinypic.com/21ahjt.png This is after the admin tries to login, it's meant to redirect to adminData.php but it doesn't http://i58.tinypic.com/23m1r8p.png
Login.html Code
<!DOCTYPE html>
<html>
<head>
<title>Sign In</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/style.css"/>
</head>
<body>
<div id="container">
<header>
<a href="index.html"><img src="images/Header.jpg" alt="logo" /></a>
<a href="login.html"><img src="images/login.jpg" alt="login" /></a>
<a href="https://www.facebook.com/ArcticMonkeys"><img src="images/Facebook.jpg" alt="FB" /></a>
<a href="https://twitter.com/arcticmonkeys"><img src="images/Twitter.jpg" alt="Twitter" /></a>
</header>
<div class="menu">
<div align="center">
<ul class="list">
<li class="item"><a href="index.html">Home</a>
<li class="item"><a href="gallery.html">Gallery</a>
<li class="item"><a href="videos.html">Videos</a>
<li class="item"><a href="discography.html">Discography</a>
<li class="item"><a href="register.php"#">Register</a>
<li class="item"><a href="#">About</a>
<ul class="list">
<li><a href="alex.html">Alex Turner</a></li>
<li class="list">
<a href="matt.html">Matt Helders</a>
<ul class="list">
<a href="jamie.html">Jamie Cook</a>
<ul class="list">
<a href="nick.html">Nick O'Malley</a>
<ul class="list">
<a href="andy.html">Andy Nicholson</a>
<ul class="list">
</ul>
</li>
</div>
</div>
<div align="center"><BR><BR><BR><BR>
<body id="body-color">
<div id="Sign-In">
</head>
<form action="login.php" method="post">
<table width="500" align="center">
<tr align="center">
<td colspan="3"><h2>User Login</h2></td>
</tr>
<tr>
<td align="right"><b>Email</b></td>
<td><input type="text" name="email" required="required"/></td>
</tr>
<tr>
<td align="right"><b>Password:</b></td>
<td><input type="password" name="pass" required="required"></td>
</tr>
<tr align="center">
<td colspan="3">
<input type="submit" name="login" value="Login"/>
</td>
</tr>
</table>
</form>
<br><br>
<form action="moderatorLogin.php" method="post">
<table width="500" align="center">
<tr align="center">
<td colspan="3"><h2>Moderator Login</h2></td>
</tr>
<tr>
<td align="right"><b>Email</b></td>
<td><input type="text" name="email" required="required"/></td>
</tr>
<tr>
<td align="right"><b>Password:</b></td>
<td><input type="password" name="pass" required="required"></td>
</tr>
<tr align="center">
<td colspan="3">
<input type="submit" name="Admin" value="Login"/>
</td>
</tr>
</table>
</form>
<H3>If you do not have an account please register <a href="register.html">HERE</a><br>otherwise access is restricted to member pages<h3>
</div>
</body>
</html>
moderatorLogin.php Code
<?php session_start();
// establishing the MySQLi connection
$con = mysqli_connect("localhost","root","","admin");
if (mysqli_connect_errno())
{
echo "MySQLi Connection was not established: " . mysqli_connect_error();
}
// checking the user
if(isset($_POST['login'])){
$email = mysqli_real_escape_string($con,$_POST['email']);
$pass = mysqli_real_escape_string($con,$_POST['pass']);
$sel_user = ("select * from moderators where email='$email' AND password='$pass'");
$sel_user = ("select * from moderators where email='$email' AND password='$pass'");
$run_user = mysqli_query($con, $sel_user);
$check_user = mysqli_num_rows($run_user);
if($check_user>0){
$_SESSION['email']=$email;
echo "<script>window.open('adminData.php','_self')</script>";
}
else {
echo "<script>alert('Email or password is not correct, try again!')</script>
<script>window.open('register.php','_self')</script>";
}
}
?>
Note: this website will not be hosted online, i will be looking to make it more complex in the future in terms of security and what not, but for now i just want to get what i have working before i start learning about security etc...
Any help at all is greatly appreciated.
Ryan.