我正在使用AJAX调用函数提交如下的登录表单,但是它被定向到的页面仅在发现用户不存在(正常工作)时响应,但是当登录信息被认为是正确的时,警报或其他方面没有任何回报,我错过了什么?
<script>
$(document).ready(function() {
$("#loginbutton").click(function() {
var user = $("#user").val();
var pass = $("#pass").val();
var dataString = "user="+user+"&pass="+pass;
if (user == "" || pass == "") {
alert("Please fill in all fields");
}
else {
$.ajax({
type: "POST",
url: "login.php",
data: dataString,
cache: false,
success: function(result) {
alert(result)
},
});
}
return false;
});
});
</script>
这是PHP:
<?php
include_once($_SERVER['DOCUMENT_ROOT'].'/wp-config.php');
include_once($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');
include_once($_SERVER['DOCUMENT_ROOT'].'/wp-includes/wp-db.php');
global $userdata;
global $wpdb;
//get the posted values
$posted_username = 'matt-inovate';
$posted_password = 'Qazplm10';
$user_name = htmlspecialchars($posted_username,ENT_QUOTES);
$pass_word = wp_hash_password($posted_password);
$pass_md5 = md5($posted_password);
$pass = $pass_word;
$userinfo = get_userdatabylogin($user_name);
$passcheck = $userinfo->user_pass;
$conn = mysql_connect("127.0.0.1", "fw1359063030", "75ozg3cMxM47kRlJEPdLl2iOPb3f4R") or mysql_error();
$conn = mysql_select_db("db8760018806", $conn);
$sql = "SELECT * FROM wp_users WHERE user_login = '$posted_username'";
$result = mysql_query($sql) or mysql_error();
$rows = mysql_num_rows($result);
if ($rows == 1) {
$row = mysql_fetch_array($result);
echo $passcheck."<br>";
echo $row[2]."<br>";
if ($passcheck == $row[2]) { echo "Login Success."; } else { echo "Login Failed."; }
}
else { echo "Could not find user."; }
?>