I have following PHP if/else statement - how can I tell it to go back to login.php and run jQuery function?
if($result) {
if(mysql_num_rows($result) == 1) {
//Login Successful
session_regenerate_id();
开发者_如何学运维 $member = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $member['member_id'];
$_SESSION['SESS_FIRST_NAME'] = $member['firstname'];
$_SESSION['SESS_LAST_NAME'] = $member['lastname'];
$_SESSION['SESS_LOGIN'] = $member['login'];
session_write_close();
header("location: ../index.php");
exit();
}else {
$error = true;
// go back to login.php and run jQuery function
}
}else {
die("Query failed");
// // or go back to login.php and run different jQuery function
}
you could use:
header('Location: login.php?message=query_failed');
or
header('Location: login.php?message=login_failed');
and on your login.php
inside your javascript tags
:
you can use php
for:
<?php if($_GET['message'] == 'query_failed'): ?>
jquery_query_failed_function();
<?php elseif($_GET['message'] == 'login_failed'): ?>
jquery_login_failed_function();
<?php endif; ?>
so Continuing from your else
statement: it should be:
continuing from your else statement:
else {
$error = true;
header('Location: login.php?message=login_failed');
}
}else {
header('Location: login.php?message=query_failed');
die("Query failed");
// // or go back to login.php and run different jQuery function
}
header("Location: ../login.php?error_code=1");
header("Location: ../login.php?error_code=2");
Based on the error code you would execute a different function, that's if you wanna use redirects.
精彩评论