The else part of my code is working when the password is wrong. However, when password is correct it does not go to the admin.php page. It just stays on the same page.
Does anyone know why this is happening?
<?php
session_start();
error_reporting(E_ALL); // to see if there is error in code
include "connect_to_mysql.php";
if(isset($_POST['log'])){
$user = $_POST['user'];
$pass = md5($_POST['pass']);
$sql = mysql_query("select * from login where user= '$user' AND pass='$pass' LIMIT 3 ") or die( mysql_error());
$data = mysql_fetch_array($sql);
$UserName = $data['user'];
$Password = $data['pass'];
$type = $data['type'];
$name = $data['name'];
if($user==$UserName && $pass==$Password){
session_start();
$_SESSION['name']=$name;
if($type=='admin'){
header("location: admin.php");
}else if($type=='vender1'){
header("location: vender1.php");
}
}
}
?>
The database contains: id, name, user, pass, type
So my problem is; after the right password is entered, the same page remains open, but it should open admin.php.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Log In </title>
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
</head>
<body>
<br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br />
<div id="mainWrapper">
<?php include_once("header.php") ?>
<div id="pageContent"><br /><br /><br />
<div align="right" style="margin-right:24px; color:#FF0000">
<h2>Please Log In To Manage the Inventary</h2>
<br /><br />
<form id="form" name="form" method="post" action="login.php">
<h2 style="padding-right:200px;">User Name:</h2>
<input name="user" type="text" id="user" size="40" style="height:20px;" />
<br /><br />
<h2 style="padding-right:210px;">Password:</h2>
<input name="pass" type="password" id="pass" size="40" style="height:20px;" />
<br />
<br />
<br />
<input type="submit" name="log" id="log" value="Log In" />
</form>
<p> </p>
</div>
<br />
<br />
<br />
</div>
</div>
</body>
</html>
I am stuck here.. Please get me out from here.