当检查数据库中是否使用了用户名时,代码始终显示用户名被取消的消息。如果我更改了ajax中的条件,则消息会发生变化,但即使用户在DB中,它也会显示相同的内容
$(document).ready(function() {
$("#email").keyup(provjeraEmaila);
$("#korime").blur(function() {
if ($("#korime").val().length >= 5) {
$.ajax({
type: "POST",
url: "korisnici.php",
data: {
fieldName: "korisnicko_ime",
filedVal: $("#korime").val()
},
success: [function(data) {
if (data == 0) {
$("#username-span").html("username is taken!");
$("#username-span").attr('class', 'username-span');
} else {
$("#username-span").html("username is free!");
$("#username-span").attr('class', 'username-span');
}
}]
});
$("#username-span").html("");
}
});
});
这是PHP代码:
<?php
include_once 'baza.class.php';
if (isset($_POST['registracija']))
{
$veza = new Baza();
$veza->spojiDB();
$korime = $_POST['korime'];
$upit = "SELECT korisnicko_ime FROM korisnik WHERE
korisnicko_ime='$korime'";
$rezultat = $veza->selectDB($upit);
if (mysqli_num_rows($rezultat) > 0)
{
echo 0;
}
else
{
echo 1;
}
}
?>