ajax login problem
Posted
by rdanee
on Stack Overflow
See other posts from Stack Overflow
or by rdanee
Published on 2010-05-26T15:33:38Z
Indexed on
2010/05/26
16:01 UTC
Read the original article
Hit count: 271
$(document).ready(function() {
$("form#login_form").submit(function() {
var login_username = $('#login_username').attr('value');
var login_password = $('#login_password').attr('value');
type: "POST",
$.ajax({
url: "login.php",
data: "username="+ login_username +"& password="+ login_password,
success: function(data){
alert(data);
if (data == "ok"){
$('form#login_form').hide(function(){$('div.success').fadeIn();});
}
}
});
return false;
});
Login.php:
<?php
include("settings.php");
$query = "select * from users where username = '{$_POST['login_username']}' and password = md5('{$_POST['login_password']}')";
$query = mysql_query($query, $connection);
if ( mysql_num_rows($query) == 1 )
{
print "ok";
$array = mysql_fetch_array($query);
if ( $_POST['stay'] ) { $time = time()+2592000; }
else { $time = 0; }
}
else { print "no"; }
mysql_close($connection);
?>
My problem: In the alert the message always "no" whether username/password is correct, however on the site "ok" appears when username/pw is correct.
I have read the other questions in connection with this problem, but I couldn't solve the response problem from login.php with Json. Could you help me how should I response to the ajax calling? ( with a code if it is possible) Thank you very much, and sorry for questioning again.
© Stack Overflow or respective owner