How to call bootstrap modal in php

2020-03-24 17:47发布

I'm trying to call a modal that I have in a html file which is hidden alongside another modal. One of them appears as the button is clicked but the other one is to be called by php as part of a verification process.

Here is my php code:

$File = include("index2.html");
$Msg = 'Welcome ';
$search=$_POST['search'];
$query = $pdo->prepare("SELECT * FROM students WHERE IDs LIKE '%$search%'  LIMIT 0 , 10"); //OR author LIKE '%$search%'
$query->bindValue(1, "%$search%", PDO::PARAM_STR);
$query->execute();
// Display search result
         if (!$query->rowCount() == 0) {
                 echo '<script type="text/javascript">';
                                 echo 'alert("Verification Complete");';
                                  echo '</script>';



            while ($results = $query->fetch()) {

                $Studname = $results['Studentname'];


                echo '<script type="text/javascript">';                
                echo 'alert("'.$Msg.$Studname.'")';
                echo '</script>';



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

            }

         } else {
           echo '<script language="javascript">';
            echo 'alert("Sorry your ID was not found");';
            echo 'window.location.href = "/Koleesy/index.html";';
            echo '</script>';
        }
?>

After the user is welcomed I want the hidden modal from my index.html to be called so the user can continue submitting the advert. I've tried using the include function but that doesn't seem to work in my favor. How do I do this? Every answer is appreciated.

1条回答
再贱就再见
2楼-- · 2020-03-24 18:14

Try this:

echo "<script type='text/javascript'>
$(document).ready(function(){
$('#myAdvert').modal('show');
});
</script>";
查看更多
登录 后发表回答