Salve. Ho il seguente script in ajax e php:

codice:
<script src="jquery.js" type="text/javascript" language="javascript"></script>
<script language="javascript">
$(document).ready(function()
{
	$("#login_form").submit(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#msgbox").removeClass().addClass('messagebox').text('Controllo dati....').fadeIn(1000);
		//check the username exists or not from ajax
		$.post("core/login.php",{ username:$('#username').val(),password:$('#password').val(),rand:Math.random() } ,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('Login in corso.....').addClass('messageboxok').fadeTo(900,1,
              function()
			  { 
			  	 //redirect to secure page
				 document.location='utenti/index.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('Dati errati...').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>



<form method="post" action="" id="login_form">
Username:
<input name="username" type="text" id="username" maxlength="32">
Password:
<input name="password" type="password" id="password" maxlength="32">
<input name="Submit" type="submit" id="submit" value="Login" /> 
<span id="msgbox" style="display:none">
La pagina core/login.php è questa:
codice:
<?php 
include("../connessione.php");
session_start();
$username = Filtro($_POST['username']);
$password = Filtro(md5($_POST['password']));

$sel=mysql_query("SELECT * FROM utenti WHERE username='$username' AND password='$password'");
 
if(mysql_num_rows($sel)!=1) {
	    echo "no";
} else {
        $_SESSION['logged']=1;
        echo "yes";
}

?>
Tutto funziona tranne una cosa.
ANche se metto i dati corretti mi dice Dati Errati....
Provando a fare il login andando direttamente alla pagina php, anziche passare per ajax (quindi mettendo la pagina php nella action del form) mi restituisce "yes" quindi l'utente c'è e lo trova.
Passando per ajax mi da sempre dati errati.
Dove è l'errore? (presumo sia nei codici javascript)