I developed a PHP login system that when the user logs in and the account is still not activated by the admin it will display message2 and if the user inputs wrong credentials it will display mesage1
I am almost done with the work. but i am confused on why the condition always falls under message1.
here is my code.
<?php
session_start();
if(isset($_POST["submit"])){
// windows
// $servername = "localhost";
// $username = "root";
// $password = "";
// $dbname = "loginDB";
// linux
$servername = "localhost";
$username = "root";
$password = "gmg0ddepfrxs";
$dbname = "loginDB";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn){
die("Connection failed: " . mysqli_connect_error());
}
$uname = $_POST["name"];
$password = $_POST["pwd"];
$sql = "SELECT * FROM user WHERE user_name='$uname' AND password='$password'";
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_assoc($result)){
$utype = $row["user_type"]; //1
$status = $row["user_status"]; //0
$username = $row["user_name"]; //USERNAME
$password = $row["password"]; //PASSWORD NG USER
}
if (mysqli_num_rows($result) > 0 AND $utype == '1'){
// session_start();
$_SESSION["login"] = "access";
setcookie("name",$uname,false);
echo "<script>window.location.href=\"member.php\"</script>";
}elseif (mysqli_num_rows($result) <= 0) {
echo "<script>window.location.href=\"index.php?msg=1\"</script>";
}elseif ($utype == '0') {
echo "<script>window.location.href=\"index.php?msg=2\"</script>";
}
}
?>
here is my HTML code.
<html>
<form action='login.php' method="post">
<table cellspacing='5' align='center'>
<tr>
<td>Username:</td>
<td>
<input required type='text' name='name' />
</td>
</tr>
<tr>
<td>Password:</td>
<td>
<input required type='password' name='pwd' />
</td>
</tr>
<tr>
<td></td>
<td>
<input type='submit' name='submit' value='Submit' />
</td>
</tr>
</table>
<?php if(isset($_GET[ "msg"])){
$errmsg=$ _GET[ "msg"];
if($errmsg==1 ){ echo "<div style='text-align: center;'><h5> <font color = \"red\ "> Incorrect username and/or password! have you registered? </font></div>"; }
elseif ($errmsg==2 ) { echo
"<div style='text-align: center;'><h5> <font color = \"red\ "> Contact admin to activate your account. </font></div>"; } } ?>
</form>
<div style="text-align: center;">
<a href="register.php">
<button>Register here</button>
</a>
</div>
</html>