如果条件满足则调用模态 - PHP

时间:2017-02-15 10:21:27

标签: php jquery twitter-bootstrap

我试图让条件中的模态显示得到满足,但问题是没有显示模态,有人可以帮我这个吗? php代码位于模态代码之下。

这是php

<?php
session_start();
include_once("connection.php");
if (isset($_POST['login']))
{
    $stud_no = $_POST["stud_no"];
    $password = $_POST["pword"];
    $name = mysqli_real_escape_string($con, $stud_no);
    $password = mysqli_real_escape_string($con, $password);
    $select_user = "SELECT * FROM student_accounts WHERE stud_no ='$stud_no' AND password ='$password'";
    $run_user = mysqli_query($con, $select_user);
    $check_user = mysqli_num_rows($run_user);
    if ($check_user > 0)
    {
        $_SESSION['stud_no'] = $stud_no;
        header('location: home.php');
    }
    else
    {
        echo '<script>$("#myModal").modal()</script>';
    }
}

?>

这是模态

<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">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body">
        <p>Some text in the modal.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>

2 个答案:

答案 0 :(得分:3)

您需要在运行 PHP 代码之前 INCLUDE jQuery库,以及bootstrap JS。看到结果,它会奏效。

IF 仍无法使用以下代码来回显您的脚本::

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

答案 1 :(得分:0)

替换下面的行

echo '<script>$("#myModal").modal()</script>';

echo '<script>$("#myModal").modal('show')</script>';