Guys, I know, I know, but I cant seem to effectively google what I'm looking for and I'm sure its simple.
I have this;
Which is great, but I have created another table in MySQL called 'admins' with the same field layout.
On the site I want the same login box to be effective for both users and admins yet if an admin logs in I want them redirected to an alternative page (not the survey page above).
I have tried adding a repeat of the code above and changing the selected table from 'users' to 'admins' and have shown the redirect as admin.php instead of survey.php but when submitted the login page just reloads with no errors.
I would really appreciate some pointers here.
Thanks
I have this;
Code:
<?php
session_start();
mysql_connect('localhost', 'dbuser', 'password');
mysql_select_db('dbname');
function clean($value) {
if(get_magic_quotes_gpc()) $value = stripslashes($value);
return trim(mysql_real_escape_string($value));
}
if($_POST['login'] && $_POST['username'] && $_POST['password']) {
$username = clean($_POST['username']);
$password = md5($_POST['password']);
$result = mysql_query("SELECT username FROM users WHERE username = '$username' AND password = '$password'");
if(mysql_num_rows($result) == 1) {
$_SESSION['username'] = $username;
header("Location: survey.php");
exit;
} else {
$error = '<p>Sorry, Incorrect Username and/or Password. Please try again.</p>';
}
}
?>
Which is great, but I have created another table in MySQL called 'admins' with the same field layout.
On the site I want the same login box to be effective for both users and admins yet if an admin logs in I want them redirected to an alternative page (not the survey page above).
I have tried adding a repeat of the code above and changing the selected table from 'users' to 'admins' and have shown the redirect as admin.php instead of survey.php but when submitted the login page just reloads with no errors.
I would really appreciate some pointers here.
Thanks