Jump to content

JavaScript username checker.


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";
			document.getElementById("checkUser").className = "errormsg";
			document.getElementById("checkUser").innerHTML = "Name is not available!";



$result = mysql_query("SELECT login FROM users WHERE login='".clean_string($_POST["username"])."'");

	echo 0;
	echo 1;

Link to comment
Share on other sites

Check first, what value you're sending to database. I'm pretty sureit's incorrect.


var_dump($_POST["username"]); exit; 


Note: The original MySQL extension is now deprecated and it's not recommended to use for new development. Instead, use the MySQLi or PDO_MySQL extensions.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.