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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:59:35+00:00 2026-06-10T03:59:35+00:00

This is from a register form. This function verifies if the username is available

  • 0

This is from a register form. This function verifies if the username is available or not.

jQuery:

    /* Verifies if the username is available */
    $.post('functions/usernameDisponibility.php',{usernamePHP:username},function(disponibility)
    {
            $('.usernameErrors').text(disponibility);

    if(disponibility==true)
    {
        $('#username').css('border-color','#00ff00');
    }else
        {
            $('#username').css('border-color','red');
            $('.usernameErrors').text('Username unavailable');
        }
    });

PHP:

    if(isset($_POST['usernamePHP'])&&!empty($_POST['usernamePHP']))
{
    $username = $_POST['usernamePHP'];

    $Connect = mysql_connect('localhost','root','');
                mysql_select_db('phplogin');

    $query= mysql_query("SELECT * FROM users WHERE username = '$username'");

    $result= mysql_num_rows($query);

    if($result==1)
    {
        echo false;
    }else
    {
        echo true;
    }
}

The problem is in the error display. When disponibility != true, it shows “Username unavailable”, but when it’s true it shows “1”. My guess is that “1” came from the PHP script but even if I do this:

            if(disponibility==true)
        {
            $('#username').css('border-color','#00ff00');
            $('.usernameErrors').text('');
        }else

The “1” still shows up very quickly and only then it is replace by text(”). What can I do for the “1” not be displayed at all?

  • 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-10T03:59:36+00:00Added an answer on June 10, 2026 at 3:59 am

    it’s because of this:

    $('.usernameErrors').text(disponibility);
    

    you are outputing the content of “disponibility” variable before you do any checks. Remove that line

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

Sidebar

Related Questions

Jquery: <script type=text/javascript> $(document).ready(function(){ $(form.register).change(function() { $.post(check.php, $(form.register).serialize(), function( data ) { if( data.username
I'm using this code: $j(#register-form form).submit(function() { if ($j(input:first).val() == correct) { $j(#registration-notification).animate({ height:
I got this from php.net website. This is related to the problem I am
I found this from C++FAQ Generally, No. From a member function or friend of
Having issues referencing $(this) from within a the nested ajax 'success' function... I know
On my site users fill out a form to register, this info then gets
This is the code I have. I want to prevent the form from submitting
I am creating a registration form using PHP and jquery with ajax. Each field
check the following script: from mechanize import Browser br = Browser() page = br.open('http://scottishladiespool.com/register.php')
I'm using a Jquery form on my website. The from is pretty much simple

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.