$sql="SELECT * FROM accounts,adminaccount WHERE accounts.emailaddress='$username' and accounts.password='$password' or adminaccount.emailaddress='$username' and adminaccount.password='$password'";

$result = mysql_query($sql);

$count=mysql_num_rows($result);

$row = mysql_fetch_assoc($result);

$usertype = $row['usertype'];


if($count==1)
{
	
	$_SESSION['usertype']= $row['usertype'];
	$_SESSION['id'] = $row['id'];
	if($usertype == "admin")
	{
	header("location:indexadmin.php");
	}
	else
	{
	header("location:indexmember.php");
	}
}
else
{
header("location:index.php?page=loginfail.php");
}

?>

I wanted it to go into indexadmin.php location if the account's usertype is admin else it will head to indexmember.php. But even if i log a normal user account it will still go to indexadmin.php. Help please.

Thanks in advance.

Member Avatar for diafol

redirects should always carry an exit; after them, although I don't know whether this will make a difference here - try it:

if($usertype == "admin"){
    header("location:indexadmin.php");
    exit;
}else{
    header("location:indexmember.php");
    exit;
}

Try changing to this bit of code :

$sql="SELECT * FROM accounts,adminaccount WHERE accounts.emailaddress='$username' and accounts.password='$password' or adminaccount.emailaddress='$username' and adminaccount.password='$password'";

$result = mysql_query($sql);

$count=mysql_num_rows($result);

while($row = mysql_fetch_assoc($result)){

$usertype = $row['usertype'];


if($count==1)
{
	
	$_SESSION['usertype']= $row['usertype'];
	$_SESSION['id'] = $row['id'];
	if($usertype == "admin")
	{
	header("location:indexadmin.php");
	}
	else
	{
	header("location:indexmember.php");
	}
}
else
{
header("location:index.php?page=loginfail.php");
}
}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.