I wrote the code of a registration form and a logging in form using php.But every time i run this code it says invalid username when it is invalid or it says your account isn;t approved bu admin yet.Can someone please show me how to make possible the admin approval for the user when he logs in.I want my user to be approved by the admin.Notice that the admin must log in in the same form with the user.Here is my registration form:
Here is my login form:
<html >
<head>
<title></title>
</head>
<body>
<?php
print ("<form action='logincontroltest.php' method='post'>
<p>Username
<input type='text' name='username' />
</p>
<p>Password
<input type='password' name='password' >
<p/>
<input type='submit' value='Log In'/>
</form>");
if( !($database=mysql_connect("localhost","root",""))||!(mysql_select_db("st_login",$database)) )
print("Could not connect");
if(isset($_POST['username'])&&isset($_POST['password']) )
{
$username=$_POST['username'];
$password=$_POST['password'];
if ( !empty($username) &&!empty($password) )
{
$query = " SELECT * FROM `login` WHERE `username`='$username' AND `password`='$password' ";
if($result=mysql_query($query,$database))
{
$user=mysql_fetch_assoc($result);
if($user==false){
echo "invalid username";
}
elseif($user['admin']==1) {
echo"admin is logged in";
header("Location: admin.php");
}
elseif($user['approval']==1) {
$_POST['user']=$user['username'];
echo "user is logged in";
header("Location: faqja2.php");
}
else{
echo "Your account is'nt approved by admin yet";
}
}
die (mysql_error());
}
else echo "Fill in all blank fields";
}
?>
</body>
</html>
The code works correctly! And here is the phpmyadmin database i've created: