Jump to content

Jquery username validation not working

- - - - -

  • Please log in to reply
No replies to this topic

#1
jlr2k8

jlr2k8

    Newbie

  • Members
  • Pip
  • 1 posts
I'm trying to get this to work, but it seems like the PHP validation file (register.submit.php) is reflecting no results. Register.submit.php is designed to reflect the number of users in the database. When the username does not already exists, register.submit.php will echo 0, and the registration process can continue. When the username does exist, it will find 1 record, therefore echoing 1, and the registration cannot continue.

While this script works in a basic HTML form, jquery doesn't reflect submitting the data. Basically, the data goes to the page, but its like the script loads register.submit.php without any connection to the form data. Its like going to register.submit.php through a browser instead of through a form.

Any help would be appreciated, thanks!


register.php (jquery)

<script src="http://code.jquery.com/jquery-latest.js"></script>

<script language="javascript" type="text/javascript">

$(document).ready(function(){

	$('input[name=username]').keyup(username_check);

});	

function username_check(){ 

	var username=$('input[name=username]').val();

	var str="username="+username;

	$('#loading').fadeIn('fast');

	jQuery.ajax({

		url: "register.submit.php",

		contentType: "text/XML",

		type: "POST",

		data:  str,

		cache: false,

		success: function (html){

			if (html==0){                 

				//$('input[name=username]').hide('slow');

				$('#username').html(" Good... "+html);

				$('#username').show('slow');

				$('#loading').fadeOut('fast');

			}

			else{

				$('#username').show('slow');

				$('#username').html(" Nope... "+html);

				$('#loading').fadeOut('fast');

			}

		}

	});

}

</script>


<div id="register"><form method="post" action="">

* User Name: <span id="loading" style="display:none">Loading... </span><br /><input type="text" name="username" /><b id="username" style="display:none"></b><br /><input type="submit" id="register_submit" value="I agree, submit..." />

</form></div>


register.submit.php

mysql_select_db("hsc", $con);

$username=htmlentities(mysql_real_escape_string($_POST['username']));

$result=mysql_query("SELECT COUNT(username) FROM user WHERE username='$username'",$con) or die(mysql_error());

$row=mysql_fetch_array($result);

echo $row['COUNT(username)'];






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users