提交时未显示登录失败时,Bootstrap 4模式登录关闭

时间:2018-08-03 13:13:46

标签: php twitter-bootstrap login modal-dialog bootstrap-modal

我有一个带有用户名和密码的自举php登录模式。

在提交表单时,有几项检查内容:电子邮件和密码是否匹配?电子邮件是否存在于数据库等中。

其中一项检查失败时,用户将无法登录,并且错误将存储在php中:$ error = 1;。

问题在于表单提交时模式关闭,当登录良好时就可以了。但是,当登录失败并出现错误时。比模态不应该更紧密,并且必须在模态中显示错误。

登录代码:

 <?php 
            include('connection.php');
            if (isset($_POST['proceed'])) {
                    $username = $_POST['login'];
                    $password = $_POST['password'];
                    /***** GUIDANCE *****/
                    $guidance = "SELECT * FROM faculty WHERE Faculty_ID = ? AND Password = ? AND Position='Guidance' ";
                    $stmt = $conn->prepare($guidance);
                    $stmt->bind_param('is', $username, $password);
                    $stmt->execute();
                    $result = $stmt->get_result();
                    /***** TEACHER *****/

                    $teacher = "SELECT * FROM faculty WHERE Faculty_ID = ? AND Password = ? AND Position='Teacher' ";
                    $stmt = $conn->prepare($teacher);
                    $stmt->bind_param('is', $username, $password);
                    $stmt->execute();
                    $result1 = $stmt->get_result();
                    /***** STUDENTS *****/

                    if ($result -> num_rows > 0) {

                        $row = $result -> fetch_object();
                            if($row->Status!='Active'){
                                $inactive = 1;
                            }else{
                                $_SESSION['access'] = 1;
                                $_SESSION['login'] = $row -> Faculty_ID;
                                $_SESSION['Faculty_Firstname'] = $row -> Faculty_Firstname;
                                header('Location: guidance/index.php');
                            }
                        }elseif ($result1 -> num_rows > 0) {

                            $row = $result1 -> fetch_object();
                                if($row->Status!='Active'){
                                     $inactive = 1;
                                    }else{
                                        $_SESSION['access'] = 2;
                                        $_SESSION['login'] = $row -> Faculty_ID;
                                        $_SESSION['Faculty_Firstname'] = $row -> Faculty_Firstname;
                                        header('Location: pages/teacher/index.php'); 
                                    }
                            } elseif ($result2 -> num_rows > 0) {

                                    $row = $result2 -> fetch_object();
                                        $_SESSION['access'] = 3;
                                        $_SESSION['Student_ID'] = $row -> Student_ID;
                                        //$_SESSION[] = $row -> 
                                        header('Location:student/index.php ');
                        }else{
                                    $error = 1;
                    }

                }   
         ?>

引导程序模式代码:

<div class="modal fade modal-open" role="dialog" id="loginModal1">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h3 class="modal-title">Account Login</h3>
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                            <div style="padding-top:30px" class="panel-body" >
                        <div class="alert alert-danger <?php if(!isset($error)) echo 'hide';?>" style="margin-top: -10px">
                            Invalid username/password! Email administrator in link below to recover it.
                      </div>

                      <div class="alert alert-warning <?php if(!isset($inactive)) echo 'hide';?>" style="margin-top: -10px">
                            This account is no longer valid. Thank you!
                      </div>

                        <div style="display:none" id="login-alert" class="alert alert-danger col-sm-12"></div>
                    </div>
                    <div class="modal-body">
                        <form method="post">
                            <div class="form-group">
                                <label for="email">ID:</label>
                                <input type="text" class="form-control" required name="login">
                            </div>
                            <div class="form-group">
                                <label for="password">Password:</label>
                                <input type="password" class="form-control" required name="password">
                            </div>
                            <div class="modal-footer">
                                <button type="submit" class="btn btn-warning text-white " name="proceed">Signin</button>
                            </div>
                        </form>
                    </div>

                </div>
            </div>
        </div>

0 个答案:

没有答案