Hi guys,
Just questions I have this log in page called index.php - but at the moment I can only add one admin.
How can I add if there are more than one admin? Using level '1' and '0'?
Here is my log in code:
index.php
<?php
session_start();
$error_msg = "";
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("persons") or die ("Couldn't find the DB");
$query = mysql_query ("SELECT * FROM `users` WHERE username = '$username'");
$numrows = mysql_num_rows($query);
//echo $numrows;
//If $numrows != 0 there is a records in DB, then do the following
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)
{
$_SESSION['username'] = $username;
$_SESSION['is_admin'] = false;
if ( $username == 'admin' )
{
$_SESSION['is_admin'] = true;
}
header("Location: firstpage.php");
}
else
$error_msg = "Incorrect password!";
//code of login
}else
$error_msg = "That user does not exist!";
}
else
$error_msg = "Please enter a username and password!";
}
?>
<html>
<head><title>Login Page</title>
</head>
<body>
<br />
<?php
require "header.php";
?><br />
<br />
<div align="center">
<table width="200" border="1">
<?php
// If $error_msg not equal to emtpy then display error message
if($error_msg!="") echo "<div id=\"error_message\"style=\"color:red; \">$error_msg</div><br />";
?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<!--form action="login_a.php" method="post"-->
Username: <input type="text" name="username" /><br /><br />
Password: <input type="password" name="password" /><br /><br />
<input type="submit" name = "submit" value="Log in" />
</form> <p> </p>
</table>
</div>
</body>
</html>
So once admin login he/she can add another admin ie:
Name
Surname
Login
Password
<Button> [Add]
Any help would be highly appreciated.
Thanks.