dsvbtgo639708 2018-08-03 13:13 采纳率: 0%
浏览 78

Bootstrap 4模态登录在提交时没有显示登录失败关闭

I have a bootstrap php login modal with username and password..

There is a check when I submit my form for several thing: Do the email and password match? Does the email exist in the database etc.

When one of the checks fails the user will not login and an error will be stored in the php: $error = 1;.

The problem is that the modal closes when the form submits, which is fine when the login is good. But when the login fails and a error appears. Than the modal should not be close and the error must be shown in the modal.

Login code:

 <?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;
                    }

                }   
         ?>

Boostrap modal code:

<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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 yolov8边框坐标
    • ¥15 matlab中使用gurobi时报错
    • ¥15 WPF 大屏看板表格背景图片设置
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥16 mybatis的代理对象无法通过@Autowired装填
    • ¥15 可见光定位matlab仿真