I know I can connect to the database. I had checked it before I revised my code.
When the admin logs in I want to redirect to tableedit.php but if the user is not the admin I want to redirect to tableuser.php.
This is the error:
Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in C:\xampp\htdocs\joy\inventory\login.php on line 47 Query failed
Here's the code:
//Create query
$qry="SELECT * FROM user WHERE username='$username' AND password='".md5($_POST['password'])."'";
while($row=mysql_fetch_array($qry));
$result = $row['username'];
{
//Check whether the query was successful or not
if($result) {
if(mysql_num_rows($result)== 'admin'){
session_regenerate_id();
$member = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $member['id'];
$_SESSION['SESS_FIRST_NAME'] = $member['username'];
$_SESSION['SESS_LAST_NAME'] = $member['password'];
session_write_close();
header("location: tableedit.php");
exit();
}
elseif(mysql_num_rows($result) != 'admin') {
//Login Successful
session_regenerate_id();
$member = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $member['id'];
$_SESSION['SESS_FIRST_NAME'] = $member['username'];
$_SESSION['SESS_LAST_NAME'] = $member['password'];
session_write_close();
header("location: tableuser.php");
exit();
} else {
//Login failed
$errmsg_arr[] = 'Username and password not found.';
$errflag = true;
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: index.php");
exit();
}
}
} else {
die("Query failed");
}}