I've created a column named 'permissions' in my database table with the value 1 for administrator and 2 for the regular users. The problem is whenever I log in with a normal user, it keeps redirecting me to the admin's page.
<?php
$con=mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('user_registration') or die("cannot select DB");
if(isset($_POST["login"])){
if(!empty($_POST['user']) && !empty($_POST['pass'])) {
$user = strip_tags($_POST['user']);
$pass = strip_tags($_POST['pass']);
$query=mysql_query("SELECT * FROM users WHERE username='".$user."' AND password='".$pass."'");
$numrows=mysql_num_rows($query);
$permissions= "SELECT username FROM users WHERE permissions = '1'";
$result=mysql_query($permissions);
if($numrows!=0) {
while($row=mysql_fetch_assoc($query)) {
$dbusername=$row['username'];
$dbpassword=$row['password'];
}
if($user == $dbusername && $pass == $dbpassword) {
session_start();
$_SESSION['sess_user']=$user;
if (mysql_num_rows($result) == 1 ) {
header("Location: fullDB.php");
} else {
header("Location: member.php");
}
}
} else {
echo "Invalid username or password!";
}
} else {
echo "All fields are required!";
}
}
?>