Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7896849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:59:57+00:00 2026-06-03T07:59:57+00:00

I am having trouble to get my code working. As a user types in

  • 0

I am having trouble to get my code working. As a user types in a username it checks the database to see if it exists and if it does sets the <P id="checkusername"> to “Username Taken.” and if not sets it to “Not Taken.” I can’t see why my code is not working.

1-register.html

<html>
  <body>
    <CENTER>
      <form name="register" action="register.php" method="post">
        Username: <input type="text" name="username" onkeyup="checkUsername(this.value)" />
        <P id="checkusername">checker</P> 
        <input type="submit" value="Login" />      
      </form>
    </CENTER>

    <script type="text/javascript">
      function checkUsername(){
        var xmlhttp;
        var username=document.forms["register"]["username"].value;
        if(username.length==0){
          document.getElementById("checkusername").innerHTML="Empty";
          return;
        }
        if(window.XMLHttpRequest){
          xmlhttp=new XMLHttpRequest();
        }else{
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }

        var url = "login.php";
        var params = "header=checkusername&username="+username+"&password="";
        xmlhttp.open("POST", url, true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.setRequestHeader("Content-length", params.length);
        xmlhttp.setRequestHeader("Connection", "close");

        xmlhttp.onreadystatechange = function() {//Call a function when the state changes.
    if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
          document.getElementById("checkusername").innerHTML=xmlhttp.responseText;
    }
      }
      xmlhttp.send(params);
    }
    </script>
  </body>
</html>

2-register.php

<?php
  $header = $_POST["header"];
  if(header=="checkusername"){
    checkusername($_POST["username"]);
  }else{
    echo "No match: " . $header;
  }

  function connection(){
    $con = mysql_connect(URL, username, password);
    if(!$con){
      die('Could not connect: ' . mysql_error());
    }
    return $con;
  }
  function checkusername($username){
    $con = connection();
    mysql_select_db(database, $con);
    $result = mysql_query("SELECT * FROM users WHERE username = \"" . $username . "\";");
    while($row = mysql_fetch_array($result)){
      if(($row['username'] == $username)){
        echo "Username Taken.<br/>";
        return;
      }
    }
    echo "Not Taken.";
  }
  mysql_close();
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:59:58+00:00Added an answer on June 3, 2026 at 7:59 am

    Read this Blog http://papermashup.com/jquery-php-mysql-username-availability-checker/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble working out how to get a simple fade in fade
I'm having trouble getting Jackson mixins working for embedded types when using @ResponseBody. I'm
I am having trouble getting a success: function(){} working - the ajax code I
I'm having some trouble getting a search by zip code proximity query working. I've
I'm having a small bit of trouble trying to get this piece of code
I'm having trouble with my program crashing. I get that Program.exe has stopped working
I am having trouble trying to get iterators for inner sub-containers. Basically imagine this
I am having trouble trying to get NAnt to compile my project, which consists
I am having trouble trying to get a group of li tags to align
I'm having a real trouble to get accents right, and I believe this may

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.