I have a sign in form. When user enter wrong password or email the the php code is checking it and the ajax gives him an alert some div id width some fade effect.
but the issue is that when the user put the right email and password i need him to redirect to the index page, instead it shows me the index page inside the fade effect div.
How do i redirect the user to the index page ?
Html code:
<form action="./sign_in.php" method="post" id="form_sign_in">
<input type="text" name="sign_in_email" id="sign_in_email">
<input type="text" name="sign_in_pass" id="sign_in_pass">
<input type="submit" name="connect" id="connect" value="Go">
</form>
Sign in function:
function sign_in_func($user_email, $user_pass) {
$user_email = mysql_real_escape_string($user_email);
$user_pass = mysql_real_escape_string($user_pass);
$query = "SELECT user_id FROM users WHERE user_email = '{$user_email}' AND user_pass = '{$user_pass}' limit 1";
$result = mysql_query($query);
$count = mysql_num_rows($result);
if ($count == 1) {
while ($row = mysql_fetch_array($result)) {
$_SESSION['user_id'] = $row['user_id'];
return TRUE;
}
} else {
return FALSE;
}
sign is php code:
if (isset($_GET['sign_in_email']) && !empty($_GET['sign_in_email'])) {
$user_email = $_GET['sign_in_email'];
} else {
echo 'Email is required <br>';
}
if (isset($_GET['sign_in_pass']) && !empty($_GET['sign_in_pass'])) {
$user_pass = $_GET['sign_in_pass'];
} else {
echo 'Pass is required <br>';
}
if (isset($_GET['sign_in_email']) && !empty($_GET['sign_in_email']) && isset($_GET['sign_in_pass']) && !empty($_GET['sign_in_pass'])) {
if (sign_in_func($user_email, $user_pass)) {
header("location: ../../index.php");
} else {
echo 'Wrong email or password';
}
}
The ajax code
$('#form_sign_in').submit(function(){
var sign_in_email = $('#sign_in_email').val();
var sign_in_pass = $('#sign_in_pass').val();
$.ajax({
url: 'scripts/php/sign_in.php',
data: { sign_in_email: sign_in_email, sign_in_pass: sign_in_pass },
success: function(data){
$('#signInFeedback').html(data);
$('#signInFeedback').fadeIn('slow', function(){
$('#signInFeedback').fadeOut(5000);
});
}
});
return false;
});