I have login form with username and password.If i am entering wrong username or password it is showing blank page not displaying any error messages.it just showing in URL as website.com/Admin/#. Here is the code which i have written:
<form action="#" method="post" role="form" enctype="multipart/form-data">
<?php if ( $msg != '' ) { ?>
<div class="alert alert-success">
<?php echo $msg; ?>
</div>
<?php } ?>
<div class="form-group col-md-12 col-sm-12 col-xs-12">
<div class="field-label">Email</div>
<input type="text" placeholder="User Name" id="username" name="user_name" required>
</div>
<div class="form-group col-md-12 col-sm-12 col-xs-12">
<div class="field-label">Password</div>
<input type="password" placeholder="Password" id="password" name="password" required>
</div>
<div class="form-group col-md-12 col-sm-12 col-xs-12">
<div class="button-box">
<input type="submit" name="submit_login" value="Sign In" class="theme-btn btn-style-one">
</div>
</form>
PHP Code:
<?php
session_start();
include 'db.php';
if ( isset( $_POST['submit_login'] ) ) {
if ( !empty( $_POST['user_name'] ) && !empty( $_POST['password'] ) ) {
$get_user_name = mysqli_real_escape_string( $conn, $_POST['user_name'] );
$get_password = mysqli_real_escape_string( $conn, $_POST['password'] );
// Encrypting the password from text//
$get_password = md5( $get_password );
$sql = "SELECT * FROM users WHERE username = '$get_user_name' AND user_password = '$get_password'";
if ( $result = mysqli_query( $conn, $sql ) ) {
while ( $rows = mysqli_fetch_assoc( $result ) ) {
if ( mysqli_num_rows( $result ) == 1 ) {
$_SESSION['user'] = $get_user_name;
$_SESSION['password'] = $get_password;
$_SESSION['user_role'] = $rows['user_role'];
if ( $_SESSION['user_role'] === 'admin' ) {
header( 'Location:property-list.php' );
}
} else {
$msg = 'User name or Password was Wrong!';
$msgclass = 'bg-danger';
}
}
} else {
$msg = 'There is somekind of Database Issue!';
$msgclass = 'bg-danger';
}
} else {
$msg = 'User name or Password was empty!';
$msgclass = 'bg-danger';
}
} else {
}
?>
If i give correct username and password its working fine their was no issue in that the only problem is with if i enter wrong username or password or else submitting directly without giving any data it is not displaying message