So I have 2 tables named tbl_admin and tbl_users. Each of them has a column named acct_type. All acct_type values in tbl_admin is 1 and in tbl_users, 0. I know it would be easy for me if I have just created one table for them. My question is, how can I query this so that I can redirect the admin to its page and the users to its page.
Here is my code
$uname = $_POST['txt_un'];
$pword = sha1($_POST['txt_pw']);
$query = "SELECT * FROM tbl_admin WHERE uname=? AND pword=?";
$stmt = $dbc->prepare($query);
$stmt->bindParam(1, $uname);
$stmt->bindParam(2, $pword);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ($row > 0) {
if ($row['acct_type'] == 1) {
header("Location: adminpage.php");
} elseif ($row['acct_type'] == 0) {
header("Location: userspage.php");
}
} else {
echo "<script>alert('Incorrect username/password');location.href='../index.php'</script>";
}
I know it will not work since I am only querying select from tbl_admin. Your help would be very much appreciated, thank you!