0

I'm trying to open bootstrap modal after login failed, I used the following code:

if (mysqli_num_rows($query) != 0)
{
    // Login successfully
}
else
{ 
    //Login failed
    echo '<script type="text/javascript"> $("#LoginFailed").modal("show")</script>';
} 

And I incloud jQuery 1.12.4 in HTML head

<script src="js/jquery-1.12.4.js"></script>

Nothing happen, The LoginFailed modal not showing up !!

I also trying the solution HERE but no luck.

Any help?

7
  • Do you include jquery? Can you show console tab in web browser? Commented Jun 10, 2019 at 10:50
  • Note that in the answer you linked, the modal code is wrapped in document.ready(). Have you tried this? Commented Jun 10, 2019 at 10:51
  • so you must be load the jquery script before this code Commented Jun 10, 2019 at 10:54
  • @RyanNghiem I incloud jQuery 1.12.4 in HTML head Commented Jun 10, 2019 at 10:59
  • @sanjundev I incloud jQuery 1.12.4 in HTML head Commented Jun 10, 2019 at 10:59

2 Answers 2

2

See exemple

I tried to tailor the exemple to yours. NOTE: In JSFiddle it will not be accurate since it only runs js css and HTML

You need to use

jQuery(document).ready(function (e) {
    // Your Modal
}
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks you so much, It's work but only if I put the PHP code in at the end of the page, And If the login information correct I used header('location:index.php') to redirect to the index .. So whereas the headers must be invoked before any output is made, It's not work .. any Idea ?
If I understand correctly, you should check if the user is logged in or not at the beginning of the code. If it is, it redirects to the home page, otherwise to login page. This prevents you from loading what you do not need and should not for the user.
Hemrique This is what I do, in the top of page I check if the user credential is correct or not, If correct I redirect it using header('location:index.php') if not I want to popup a modal with error message. The problem that If I but this code in the top of the page "before html head" the header work and the popup not, and vice versa !! Hope this clear.
Thank you so much, I really appreciate your help, It's work now ... Thaaaank you.
0

you should include bootstrap.min.js file after jquery-1.12.4.js

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.