title: jQuery call modal from PHP script
body: <p>I am creating a login script that checks if the user exists in the table.  </p>
  
  <p>In the event that the user doesn't exist, I want to use jquery to open a modal window letting the user know there was an error.</p>
  
  <pre><code> &lt;?php
     include("../include/database.php");
     if(isset($_GET['loginSubmit']))   // form submit button
     {
   // form username and password values
       $username = strip_tags(mysqli_real_escape_string($dbc, trim($_GET['username'])));
       $password = strip_tags(mysqli_real_escape_string($dbc, trim(md5($_GET['password']))));
  
   // set query
       $select = "SELECT username, fullname, userlevel, `password` FROM users WHERE username = '".$username."'"; 
   // run query
       $query = mysqli_query($dbc, $select);
   // get the results
       $row = mysqli_fetch_array($query);
   // set the results to variables to be used in sessions
       $dbusername = htmlentities(stripslashes($row['username']));    
       $dbfullname = htmlentities(stripslashes($row['fullname']));
       $dbuserlevel = htmlentities(stripslashes($row['userlevel']));
       $dbpassword = htmlentities(stripslashes($row['password']));
  
   // check if the database password matches the user password
       if($dbpassword == $password)
       {
   // if yes, set the sessions and direct to main page
         $_SESSION['username'] = $username;
         $_SESSION['fullname'] = $dbfullname;
         $_SESSION['userlevel'] = $dbuserlevel;
         header("Location:main.html"); 
       }
       else
       {
   // if no match, this is where I want the javascript to show the modal
         echo ("&lt;script language='javascript'&gt;
                $('#errLoginModal').modal('show');  // this is jquery and I know it's incorrect
                window.location.href='index.php'
                &lt;/script&gt;");
       }  
   ?&gt;
  </code></pre>
  
  <p>I am still trying to get better with JavaScript, jQuery, and PHP.  With Stack Overflow, I have been getter getting better.</p>
  
  <p>I want the PHP script to use JavaScript/jQuery to fire a modal window when the username/password check fails.  I am not even sure if this is the best method.   </p>
  
  <p>I know the code above is incorrect.  I mean it doesn't show the modal window for one.</p>
  
  <p>On the other hand, I can add an alert, and it fires the alert like so:</p>
  
  <pre><code> else
   {
     echo ("&lt;script language='javascript'&gt;
            alert(test);
            window.location.href='index.php'
            &lt;/script&gt;");
   }
  </code></pre>
  
  <p>This works.  I just would like it to be able to show the modal.</p>