Сохранить ошибку входа пользователя в модальное поле
<?php require('db.php'); session_start(); // If form submitted, insert values into the database. if (isset($_POST['username'])){ $username = stripslashes($_REQUEST['username']); // removes backslashes $username = mysqli_real_escape_string($con,$username); //escapes special characters in a string $password = stripslashes($_REQUEST['password']); $password = mysqli_real_escape_string($con,$password); //Checking is user existing in the database or not $query = "SELECT * FROM `users` WHERE username='$username' and password='".md5($password)."'"; $result = mysqli_query($con,$query) or die(mysqli_error()); $rows = mysqli_num_rows($result); if($rows==1){ $_SESSION['username'] = $username; header("Location: index.php"); // Redirect user to index.php } else{ echo "<div class='form'><h3>Username/password is incorrect.</h3><br/>Click here to <a href='login.php'>Login</a></div>"; } }else{ ?> <div class="container"> <div class="col-lg-3 mx-auto"></div> <div class="col-lg-4 mx-auto"></div> <div class="col-lg-3 mx-auto"></div> <div class="row vertical-center-row"> <div class="col-lg-5 mx-auto"><br/> <h3 class="text-center">LOGIN HERE</h3> <div class="form"> <form action="" method="post" name="login" style="text-align:center"> <input class="unbox" type="text" name="username" placeholder="Username" required /><br/><br/> <input class="unbox" type="password" name="password" placeholder="Password" required /><br/><br/> <input name="submit" type="submit" value="Login" /> </form> <p>Not registered yet? <a href='registration.php'>Register Here</a></p> <br /><br /> </div> </div> </div> </div> <?php } ?>
Что я уже пробовал:
<?php require('db.php'); session_start(); // If form submitted, insert values into the database. if (isset($_POST['username'])){ $username = stripslashes($_REQUEST['username']); // removes backslashes $username = mysqli_real_escape_string($con,$username); //escapes special characters in a string $password = stripslashes($_REQUEST['password']); $password = mysqli_real_escape_string($con,$password); //Checking is user existing in the database or not $query = "SELECT * FROM `users` WHERE username='$username' and password='".md5($password)."'"; $result = mysqli_query($con,$query) or die(mysqli_error()); $rows = mysqli_num_rows($result); if($rows==1){ $_SESSION['username'] = $username; header("Location: index.php"); // Redirect user to index.php } else{ <pre><script type="text/javascript"> $(document).ready(function(){ $("#myModal").modal('show'); }); </script>
}
}еще{
?>
<!-- Modal --> <div id="myModal" class="modal fade" role="dialog"> <div class="modal-dialog"> <!-- Modal content--> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title">Modal Header</h4> </div> <div class="modal-body"> <p>User name/password is wrong</p> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div>
<?php } ?>