Hi guys, I wonder if anyone here can assist me - I am creating a form for user login and admin login on the same page. The only different is that when the User login it will redirect them to the index page where they can only view, and create and edit their own details within the department they are in. And the admin can do everything.
I have created the login form but I do not know how I can create the admin login on it? Can you please help me out.
Here is the login.php form: (Those user who has not register will click the register link redirect them to the registration form and back to login page. But the admin password and username is set e.g. Username: admin. PW: 123456.
<?php
if (isset($_POST['submit'])) {
$username = (isset($_POST['username'])) ? $_POST['username'] : '';
$password = (isset($_POST['password'])) ? $_POST['password'] : '';
if($username && $password) {
$connect = mysql_connect("localhost", "root", "") or die ("Couldn't connect!");
mysql_select_db("friendsdb") or die ("Couldn't find the DB");
$query = mysql_query ("SELECT * FROM `user` WHERE username = '$username'");
$numrows = mysql_num_rows($query);
if ($numrows != 0){
while ($row = mysql_fetch_array($query)) {
$dbusername = $row['username'];
$dbpassword = $row['password'];
}
//Check to see if they are match!
if ($username == $dbusername && md5($password) == $dbpassword) {
echo "You are in! <a href = 'member.php'> Click </a> here to enter the member page!";
$_SESSION['username'] = $username;
}
else
echo "Incorrect password!";
//code of login
}else
echo "That user does not exist!";
//echo $numrows;
}
else
echo "Please enter a username and password!";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<!--form action="login.php" method="post"-->
Username: <input type="text" name="username" /><br />
Password: <input type="password" name="password" /><br />
<input type="submit" name="submit" value="Log in" />
</form> <p>
<a href="register.php">Register?</a>
</body>
</html>