Jump to content

Username Check Problem


fry2010

Recommended Posts

Can someone help. I have found this tutorial on checking username input, but I cannot get it to work. Iv looked at so many tutorials but just 'dont get it'.

 

http://www.ebrueggeman.com/blog/ajax/php-ajax-username-example/php_ajax_framework.js

 

Why is it the tutorial doesnt just go through steps such as:

 

step 1: do this, you will need this etc..

step 2: now do this ....

etc...

 

Instead its jumbled up and doesnt even work when I use everything.

 

Ok so what I have is the main php_javascript_framework.js file.

I have this in my main php page:

 

<?php 
$username = trim($_GET['username']);

if (usernameExists($username)) {
  echo '<span style="color:red";>Username Taken</span>';
}
else {
  echo '<span style="color:green;">Username Available</span>';
}

function usernameExists($input) {
  // in production use we would look up the username in 
  // our database, but for this example, we'll just check
  // to see if its in an array of preset usernames.
  $name_array =  array ('steve', 'jon', 'george', 'admin');

  if (in_array($input, $name_array)) {
    return true;
  }
  else {
    return false;
  }
}
?>
<html>
<head>
<link href="http://www.ebrueggeman.com/includes/styles.css" rel="stylesheet" type="text/css" media="all" />
<style type="text/css">
div{
margin-left:0;
text-align:left;
}
</style>
<script type="text/javascript" src="php_ajax_framework.js"></script>
<script type="text/javascript">
function check_username_init() {
var user_field = document.getElementById('user');
return 'username_exists.php?username=' + user_field.value;
}
function check_username_ajax(results) {
var results_div = document.getElementById('results_div');
results_div.innerHTML = results;
}
function check_username() {
var user_field = document.getElementById('user');
if (user_field.value.length > 0) {
	//call our AJAX function in the PHP AJAX Framework
	ajaxHelper('check_username');
}
else {
	//clear results field 
	var results_div = document.getElementById('results_div');
	results_div.innerHTML = '';
}
}
</script>
</head>
<body>
Username: 
<input name="user" id="user" size="20" onKeyUp="check_username();">
<div id="results_div"></div>
</body>
</html>

 

What happens is it just comes up with:

 

username available!

 

and doesnt change at all. Even when I put in names like 'steve', 'jon' which should cause it to say: not available!

 

Any help appreciated, this is incredibly annoying how no tutorials are not clear. I dont really want to learn javascript I just want this function. Thanks.

Link to comment
Share on other sites

i sorted this out yesterday.

But now I want to check the password as well. The username check is working, so I copied basically everything I used for the username but made it for the password and the password doesnt work. I have tried to seperate the files that call the php response to two seperate files :

 

check_username.php

check_password.php

 

any ideas on what im doing wrong?

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.

Guest
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.