I have an html login page. Once a user is verified through the PHP page they get redirected to another page. For some reason once I have validated that the user exists I get the message that is was successful but the page will not redirect. This is my script I use on my HTML page to pass the parameters:
$(document).ready(function() {
$('#submit').click(function() {
var username = $('input[name=username]');
var password = $('input[name=password]');
var data = 'username=' + username.val() + '&password=' + password.val();
.ajax({
url: "login.php",
type: "GET",
data: data,
cache: false,
success: function() {
alert("SUCCESS");
}
});
return false;
});
});
And this is my PHP page:
<?php
$username = ($_GET['username']) ? $_GET['username'] : $_POST['username'];
$password = ($_GET['password']) ? $_GET['password'] : $_POST['password'];
if ($_POST) $post=1;
$userFound = false;
$memberId = "";
// Create connection string, Note, params are as follow
// mysql_connect(databaseLocation, username, password)
$con = mysql_connect("localhost","root","");
if (!$con)
{
die("Could not connect: " . mysql_error());
}
mysql_select_db("memberdb", $con);
// SQL Query
$result = mysql_query("SELECT memberId, firstName, lastName, username, password FROM member");
while($row = mysql_fetch_array($result))
{
if ($username == $row["username"] && $password == $row["password"])
{
echo "<h1>Welcome " . $row["firstName"] ." ". $row["lastName"] . "! </h1></br>";
$userFound = true;
$memberId = $row["memberId"];
}
}
// If User is found, continue on to next page, if not redirect to index.html
if ($userFound)
{
echo "<h2>Login Successful</h2>";
echo "<h3>Page will redirect</h3>";
header( "url=menu.html?memberId=" . $memberId);
}
else
{
echo "<h2>LOGIN FAILED</h2>";
echo "<h3>Page will redirect</h3>";
header( "refresh: 1; url=index.html#loginPage");
}
?>
It does the echo successfully but hangs on the part where is says :
How can I get it to redirect?
Thanks