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 8937735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:28:04+00:00 2026-06-15T10:28:04+00:00

I have a form to filled out by user. Its user registration form. I

  • 0

I have a form to filled out by user. Its user registration form. I want that when user fill username text,my form should search for user name whether it exist or not.If it exist then username text field should get focus.My database table name is users and it contains column named as id,username,password,status.
Here is my code.

<form name="user" action="#" method="post">
    <label>Username</label>
    <input type="text" maxlength="25" name="username" />
    /*here i want to check from my db table weather username exists or not*/
    <label>Password</label>
    <input type="password" maxlength="25" name="password" />
    <input type="submit" value="Submit" />
</form>

I can do it when user submits the form.But my requirement is to check value with out submitting form and username should get focus.
and in php I have following code

<?php
    mysql_connect("localhost","root","") or die(mysql_error());

    mysql_select_db("test") or die(mysql_error());
    $username = $_REQUEST['username'];
    $query=mysql_query("SELECT * from user where name='$username'");
    $row=mysql_num_rows($query);
    if($row==1){
        echo "true";
    } else {
        echo "false";
    }
?>
  • 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-15T10:28:04+00:00Added an answer on June 15, 2026 at 10:28 am

    Html Form

    <form method="post" action="register.php">
        ......
        <label for="username">Username</label>
        <input type="text" maxlength="25" name="username" id="username">
        ......
    </form>
    

    Js

    <script src="jquery-1.8.0.min.js"></script>
    <script>
    $(document).ready(function(){
        $('#username').keyup(check_username); //use keyup,blur, or change
    });
    function check_username(){
        var username = $('#username').val();
        jQuery.ajax({
                type: 'POST',
                url: 'check_username.php',
                data: 'username='+ username,
                cache: false,
                success: function(response){
                    if(response == 0){
                       alert('available')
                    }
                    else {
                         alert('not available')
                         //do perform other actions like displaying error messages etc.,
                    }
                }
            });
    }
    </script>
    

    write your table user name checking in check_username.php , the response from this php is count of rows with the provided username,something like below

    <?php
        /*** mysql hostname ***/
        $hostname = 'localhost';
    
        /*** mysql username ***/
        $username = 'username';
    
        /*** mysql password ***/
        $password = 'password';
    
        /*** mysql databse ***/
        $dbname = 'database';
    
        try 
        {
            $dbh = new PDO("mysql:host=$hostname;dbname=mysql", $username, $password);
            /*** echo a message saying we have connected ***/
            //echo 'Connected to database';
        }
        catch(PDOException $e)
        {
            echo $e->getMessage();
        }   
    
        $stmt = $dbh->prepare("SELECT * FROM user where name = ?");
        $stmt->execute(array($_POST['username']));
        echo $stmt->rowCount();
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form. Once the form is filled I don't want the user
I have a web form that once filled out needs to kick off a
I have a query page with a huge form that is filled out by
I've created an app which contains form and that have to filled up in
I have form with multiple input type=radio with text next to them. I want
I have a form that I want to present in two states: 1) Normal
I have a PDF document that represents a print form that is normally filled
I have a search form built in ASP.NET that has a dropdown list which
I have a form that is suposed to help to user to choose a
I want to send the information the user has filled out from an HTML

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.