我正在使用 ajax 调用进行 login.php..以下是我的 ajax 位代码和 login.php 代码..同时提供有效的用户名和密码..我收到无效的用户名或密码消息..我完全无法理解这些代码行
$is_ajax = $_REQUEST['is_ajax'];
if(isset($is_ajax) && $is_ajax) // in login.php, Many thanks
$("#login").click(function() {
var action = $("#form1").attr('action');
var form_data = {
username: $("#username").val(),
password: $("#password").val(),
is_ajax: 1
};
$.ajax({
type: "POST",
url: login.php,
data: form_data,
success: function(response)
{
if(response == 'success')
$("#form1").slideUp('slow', function() {
$("#message").html("<p class='success'>You have logged in successfully!</p>");
});
else
$("#message").html("<p class='error'>Invalid username and/or password.</p>");
}
});
return false;
});
这是 login.php 代码。
<?PHP
if(isset($_REQUEST['is_ajax']) && $_REQUEST['is_ajax']) {
$is_ajax = $_REQUEST['is_ajax'];
$uname = $_POST['username'];
$pword = $_POST['password'];
$uname = htmlspecialchars($uname);
$pword = htmlspecialchars($pword);
$user_name = "root";
$pass_word = "root";
$database = "test";
$server = "127.0.0.1";
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$db_handle = mysql_connect($server, $user_name, $pass_word);
$db_found = mysql_select_db($database, $db_handle);
$uname = quote_smart($uname, $db_handle);
$pword = quote_smart($pword, $db_handle);
$SQL = "SELECT * FROM login WHERE L1 = $uname AND L2 = md5($pword)";
$result = mysql_query($SQL);
$num_rows = mysql_num_rows($result);
if ($num_rows > 0) {
echo "success";
}
mysql_close($db_handle);
}
?>