Jump to content

JavaScript username checker.


iRoot121

Recommended Posts

 

Hi, I'm trying to let JavaScript check if a givin user exist in the database.

 

It seems that the _check-user.php always returns 0, but if I fill in a name that doesn't exist, and echo out the result variable in JS, the echo will return 1.

 

Is there someone who could help me?

 

JavaScript part:

function checkUser() {    $.post("_check_user.php", { 'username': document.getElementById("username").value }, function(result) {        if (result == 1) {            document.getElementById("checkUser").className = "succes";            document.getElementById("checkUser").innerHTML = "Name is available";        }else{            document.getElementById("checkUser").className = "errormsg";            document.getElementById("checkUser").innerHTML = "Name is not available!";        }    });}

_check-user.php:

<?phpinclude("config.php");$result = mysql_query("SELECT login FROM users WHERE login='".clean_string($_POST["username"])."'");if(mysql_num_rows($result)>0){    echo 0;}else{    echo 1;}?>

 

Link to comment
Share on other sites

It seems that the _check-user.php always returns 0, but if I fill in a name that doesn't exist, and echo out the result variable in JS, the echo will return 1.

What does that mean, does it always return 0 or not? Have you added code inside the response handler to see what the result is set to?
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...