I am creating a login script that checks if the user exists in the table.
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.
<?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 ("<script language='javascript'>
$('#errLoginModal').modal('show'); // this is jquery and I know it's incorrect
window.location.href='index.php'
</script>");
}
?>
I am still trying to get better with JavaScript, jQuery, and PHP. With Stack Overflow, I have been getter getting better.
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.
I know the code above is incorrect. I mean it doesn't show the modal window for one.
On the other hand, I can add an alert, and it fires the alert like so:
else
{
echo ("<script language='javascript'>
alert(test);
window.location.href='index.php'
</script>");
}
This works. I just would like it to be able to show the modal.
dialogwidget would serve you best.