Jump to content

[SOLVED] Check if username exists?


Northern Flame

Recommended Posts

I a, creating a registration form for my membership program

and I want to check if the username exists before the form

is submitted. How can I do this? I attempted to do it with a

bit of javascript, but it doesn't seem to be working. Can

someone please show me how to do this or modify my script

so that it works?

 

this is how Im trying to do it.

 

<script type="text/javascript">
function nameCheck(){
var userName = document.getElementById('username').value;
var num = <?php 
$name = 'userName';
echo mysql_num_rows(mysql_query("SELECT * FROM users WHERE username='$name'"));
?>;
if(num == 1){
document.getElementById('alert').innerHTML = "Username " + userName + " Already Exists!";
}
</script>
<input type="text" name="username" id="username" size="20" onBlur="nameCheck()">

 

but that doesnt work, the mysql_num_rows returns back 0,

anybody have any ideas on how to do this?

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.