因此,当我使用正确的详细信息登录时,我的系统会给出一条带有空白消息的错误消息并且不会重定向?为什么会发生这种情况,我看不出在我的代码中如何返回空白错误?
调用它:
$("#log").click(function () {
username = $("#user").val();
password = $("#password").val();
submit = $("#log").val();
$.ajax({
type: "POST",
url: "",
data: "submit=" + submit + "&username=" + username + "&password=" + password,
success: function (response) {
if (response == 'success') {
//should never be called?
} else {
$("#error-log").remove();
var error_msg = response;
$("#s-log").append('<div id="error-log" class="err welcome dismissible">' + error_msg + '</div>');
}
}
});
return false;
});
检查:
if($_POST['submit']=='Login')
{
// Checking whether the Login form has been submitted
$err = array();
// Will hold our errors
if(!$_POST['username'] || !$_POST['password'])
$err[] = 'All the fields must be filled in!';
if(!count($err))
{
$_POST['username'] = mysql_real_escape_string($_POST['username']);
$_POST['password'] = mysql_real_escape_string($_POST['password']);
$_POST['rememberMe'] = (int)$_POST['rememberMe'];
// Escaping all input data
$row = mysql_fetch_assoc(mysql_query("SELECT id,usr FROM members WHERE usr='{$_POST['username']}' AND pass='".md5($_POST['password'])."'"));
if($row['usr'])
{
// If everything is OK login
$_SESSION['usr']=$row['usr'];
$_SESSION['id'] = $row['id'];
$_SESSION['rememberMe'] = $_POST['rememberMe'];
// Store some data in the session
setcookie('FRCteam3482Remember',$_POST['rememberMe']);
header("Location: workspace/index.php");
echo 'success';
}
else $err[]='Wrong username and/or password!';
}
if(count($err)) {
$_SESSION['msg']['login-err'] = implode('<br />',$err);
// Save the error messages in the session
echo $_SESSION['msg']['login-err'];
//php unset($_SESSION['msg']['login-err']);
//header("Location: index.php");
}
exit;
}