Modal不想显示在login.php页面上

问题描述 投票:0回答:1

我在页面的开头有这个,php检查密码和电子邮件是否在数据库中,何时不显示错误-并且错误应该在模式中:

 <?php
    session_start();
    session_destroy();
    ?>


    <?php 
    session_start();
    $pdo = new PDO('mysql:host=localhost;dbname=******', '*****', '******');

    if(isset($_GET['login'])) {
        $email = $_POST['email'];
        $passwort = $_POST['passwort'];

        $statement = $pdo->prepare("SELECT * FROM users WHERE email = :email");
        $result = $statement->execute(array('email' => $email));
        $user = $statement->fetch();

        //Überprüfung des Passworts
        if ($user !== false && password_verify($passwort, $user['passwort'])) {
            $_SESSION['userid'] = $user['id'];
            header("Location: http://localhost/app/index.php");
        } else {

            $errorMessage = "<script type='text/javascript'>
            $(document).ready(function(){
            $('#modal1').modal('show');
            });
            </script>";
        }
    }
    ?>

并且在页面末尾:

 <!-- Modal Structure -->
  <div id="modal1" class="modal modal-fixed-footer">
    <div class="modal-content"> 
      <h4>Modal Header</h4>
      <p>Wrong Password or wrong Email!</p>
    </div>
    <div class="modal-footer">
      <a href="#!" class="modal-action modal-close waves-effect waves-green btn-flat ">Agree</a>
    </div>
  </div>

我不明白为什么不显示模态,因为我在“ DOM准备就绪”后运行jquery函数,这意味着它应该看到位于描述模态的页面末尾的materialize.js。

感谢您的帮助。

javascript php jquery modal-dialog
1个回答
0
投票

在提交每个表单页面重新加载后的php中。为此,您不能显示模式。然后填充$errorMessage,但没有回显它。我建议您使用js来显示模态或比使用ajax更好如果登录失败,则必须将用户重定向到登录页面,但在url中显示一条消息像这样login.php?msg=Login_Failed并使用js可以搜索

if(location.search === "msg=Login_Failed"){
           //run modal or sweet alert or anything 
       }

或您可以使用ajax提交表单

<script>
var username = document.getelementbyid('username').value;
var password = document.getelementbyid('password').value;
 $.post("your_php_file.php",
  {
    username: username,
    password: password
  },
  function(data){
   if(data == true){
window.location.href = "app/index.php";
}else{
//run modal or anyting here
}
  });
</script>
© www.soinside.com 2019 - 2024. All rights reserved.