Good Morning,
I am recently new to php development and have come across an issue that I can't quite get my head around and need some assistance if possible.
I have been tasked to build a Task Logger in php which I have successfully done and is working fine, the current login system works well and store a session of the username that is logged in, this issue I have now come across is I want to be able to separate the log user types for example admin, user and suspended account into sections, I have added a column in my sql table called 'admin' which uses number 0,1 and 9, with 9 being an admin user. I have compiled some code after doping research into it, but when trying to log in I am getting a blank page, I am now stuck!!, I have attached my code below
<?php
session_start();
include('config.inc');
$isAdmin = mysql_query("SELECT * FROM user WHERE (username = '" . mysql_real_escape_string($_POST['username']) . "') and (password = '" . mysql_real_escape_string(md5($_POST['password'])) . "') and admin = '9'");
if(mysql_num_rows($result) == 1) {
$_SESSION['username'] = $_POST['username'];
header("Location: main.php?admin=1");
exit;
$result = mysql_query("SELECT * FROM user WHERE (username = '" . mysql_real_escape_string($_POST['username']) . "') and (password = '" . mysql_real_escape_string(md5($_POST['password'])) . "') and admin = '1'");
if(mysql_num_rows($result) == 1) {
$_SESSION['username'] = $_POST['username'];
header("Location: main.php");
exit;
$result = mysql_query("SELECT * FROM user WHERE (username = '" . mysql_real_escape_string($_POST['username']) . "') and (password = '" . mysql_real_escape_string(md5($_POST['password'])) . "') and admin = '0'");
if(mysql_num_rows($result) == 1) {
header("Location: index.php?error=3");
exit;
} else {
header("Location: index.php?error=1");
}
}
?>
My old code looked like this below and would like to utilise it for my situation
<?php
session_start();
include('config.inc');
$login = mysql_query("SELECT * FROM user WHERE (username = '" . mysql_real_escape_string($_POST['username']) . "') and (password = '" . mysql_real_escape_string(md5($_POST['password'])) . "')");
if (mysql_num_rows($login) == 1) {
$_SESSION['username'] = $_POST['username'];
header('Location: main.php');
}
else {
header('Location: index.php?error=1');
}
?>
I understand that these type of question have been asked many times before and I apologies in advance but I am unable to find anything to resolve this issue, it would be great to finally get this working!
Thanks in advance
Martin