Hi all,
I have a login form i want to be ajaxed only issue is im getting login failed this is my ajax and html form its as below
<script language="javascript">
// Developed by Roshan Bhattarai
// Visit http://roshanbh.com.np for this script and more.
// This notice MUST stay intact for legal use
$(document).ready(function()
{
$("#login_form").submit(function()
{
//remove all the class add the messagebox classes and start fading
$("#msgbox").removeClass().addClass('messagebox').text('Validating....').fadeIn(1000);
//check the username exists or not from ajax
$.post("alogin.php",{ user_name:$('#username').val(),password:$('#password').val()
} ,function(data)
{
if(data=='yes') //if correct login detail
{
$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
{
//add message and change the class of the box and start fading
$(this).html('Logging in.....').addClass('messageboxok').fadeTo(900,1,
function()
{
//redirect to secure page
document.location='secure.php';
});
});
}
else
{
$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
{
//add message and change the class of the box and start fading
$(this).html('Your login detail sucks...').addClass('messageboxerror').fadeTo(900,1);
});
}
});
return false; //not to post the form physically
});
//now call the ajax also focus move from
$("#password").blur(function()
{
$("#login_form").trigger('submit');
});
});
</script>
<!-- Show Message for AJAX response -->
<form method="post" action="" id="login_form">
<div align="center">
<div style="color:#FFF;">
User Name : <input name="username" type="text" id="username" value="" maxlength="20" />
</div>
<div style="margin-top:5px;color:#FFF;">
Password :
<input name="password" type="password" id="password" value="" maxlength="20" />
</div>
<div class="buttondiv" style="color:#FFF;">
<input name="Submit" type="submit" id="submit" value="Login" style="margin-left:-10px; height:23px" style="color:#FFF;" />
<span id="msgbox" style="display:none" style="color:#FFF;"></span>
</div>
</div>
below is my php page which as follows also nothing fancy just the usual login form as it shud work when i click on login but it deosnt when using ajax it is this
$password = mysqli_real_escape_string($con,stripslashes(trim($_POST['password'])));
$cQuery="SELECT * FROM admin WHERE username='".$username."' AND password='".$password."'";
echo $cQuery;
$con;
$rs=mysqli_query($con,$cQuery);
if(!$rs)
{
echo "Unable to excute the query:".mysqli_error($con);
}
else
{
$count=$rs->num_rows;
if($count>0)
{
if($data['password']=$password)
{
echo "yes";
//now set the session from here if needed
$_SESSION['u_name']=$username;
}
else
{
echo "Password does not match";
}
}
else
{
echo "Username doesnt exist";
}
}
Why do i get the text login stinks what am i doing wrong when i know for sure my php code and login info are correct?
i was using a tutorial and this is what the ajax/jquery tutorial said to do not sure what to do now though
any help would be good what am i doing wrong?
Thanks,William