0
All right? I’m hoping that when you lose focus, the login field will go to the bank and look for an equal login. If there is, it means the guy has to use another and for that the return must be a mistake. If there is no login like his, nothing happens and he continues to register at will.
My code js is:
function checalogin() {
$.ajax({
url: 'ajax-insere.php?login=' + $('input[name=login]').val(),
type: 'GET',
});
}
And the php code is:
if(isset($_GET['login']) && ($_GET['login'] != '')) {
$txtLogin = $_GET['login'];
$checa_login = 'SELECT * FROM usuarios WHERE login LIKE "' . $txtLogin . '"';
//echo $checa_login;
$resposta = mysql_query($checa_login) or die(mysql_error());
$value = mysql_fetch_assoc($resposta);
if ($value['login'] == $txtLogin) {
header('Location:visualiza.php?loginExiste=1');
}
}
Note that the header returns with loginExiste=1. I created a condition in php that:
if(isset($_GET['loginExiste']) && $_GET['loginExiste'] == 1) {
echo '<script>'.
'Materialize.toast('Já existe um login igual a esse. Tente algodiferente.', 7000);'.
'</script>';
}
However, when I lose focus, that is, onBlur, nothing happens. What I am doing wrong?
Thank you!
Dude, I totally understood where I was going wrong, or rather confusing. I made the changes and even changed a little but I’m still having problems. json ALWAYS returns {"isValid":true}. I tried to echo the query and it does not appear. $_GET['login'] comes. But I don’t think you’re rolling the query... you don’t think so either?
– Marcello Patto
You may need to change some things. : S Try to separate, as before, the
mysql_query
then give echo. So test in Phpmyadmin (or any Mysql manager). I don’t know if this is what you did. PHP will returntrue
if there is no datalogin = $_GET['login']
, before you used theLIKE
, what is different! Try removing themysql_real_escape_string
. You can also create a$json['Error'] = !$resposta;
this will return"Error":true
if themysql_query
not executed.– Inkeliz
SHOW, It worked. I separated the query and assigned a variable the value of mysql_real_escape_string . I didn’t even have to touch the JS. !
– Marcello Patto