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

  • Home
  • SEARCH
  • 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 7928135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:39:26+00:00 2026-06-03T19:39:26+00:00

my issue is that i have two ajax calls to php for a registration

  • 0

my issue is that i have two ajax calls to php for a registration form. First is username availability check which works absolutely fine and second is password check which does not work, database and all three files are definately connected I cant find the problem though. Thank you if someone knows it.
here is the html:

<div id="registration_form">
    <table>
         <tr>
            <td>Choose Username:</td>
            <td><input type="text" id="username" autofocus="autofocus"  /><span id="username_status"> </span></td>
         </tr>
        <tr>
            <td>Choose Password:</td>
            <td><input type="password" id="password" /> <span  id="password_status"></span></td>
         </tr>
         <tr>
            <td>Confirm Password:</td>
            <td><input type="password" id="confirmpassword" /> <span  id="pconfirm_status"></span></td>
         </tr>
        <tr>
            <td>Email:</td>
            <td><input type="text" id="email" /><span id="email_status"></span></td>
         </tr> 
         <tr>
            <td>Confirm Email:</td>
            <td><input type="text" id="confirmemail" /><span id="econfirm_status"></span></td>
         </tr>
        <tr>
            <td><input type="submit" value="Register" id="submit" />    </td>
         </tr>
    </table>
        <div id="regform_reply"></div>
</div>

Here is the jquery:

$('#password').keyup(function()
{
var password = $(this).val();
$('#password_status').text('Searching...');
    if (password != '')
    {
        $.post('php/register.php', { password: password }, function(data)
        {
            $('#password_status').text(data);
        });
    }
    else
    {
        $('#password_status').text('');
    }           
});


$('#username').keyup(function()
{
var username = $(this).val();
$('#username_status').text('Searching...');
    if (username != '')
    {
        $.post('php/register.php', { username: username }, function(data)
        {
            $('#username_status').text(data);
        });
    }
    else
    {
        $('#username_status').text('');
    }           
});

here is the php:

<?php
include '../connect/userdb_connect.php';

if (isset($_POST['password']))
{
$password = mysql_real_escape_string($_POST['password']);
if (!empty($password))
{
    if (strlen($password)>25)
    {
        echo 'Too long';
    }
    else if(strlen($password)<6)
    {
        echo 'Too short';
    }
    else
    {
        echo 'Fine';
    }
}   
}

if (isset($_POST['username']))
{
$username = mysql_real_escape_string($_POST['username']);
if (!empty($username))
{
    $check = mysql_query("SELECT `user_name` FROM `userbase` WHERE `user_name`  = '$username'");
    $result = mysql_num_rows($check);

    if ($result == 0 && strlen($username) <25)
    {
        echo 'Available';
    }
    else if($result == 1 && strlen($username) <25)
    {
        echo 'Already taken';
    }
    else
    {
        echo 'Too long';
    }
}           
}
?>
  • 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-03T19:39:29+00:00Added an answer on June 3, 2026 at 7:39 pm

    I’d go for something like :

    $('#password').on('keyup', function() {
        //there's no need to do ajax to check input length, just always validate on the server aswell
        var password = this.value;
        if (password != '') {
            $('#password_status').text('Searching...');
            if (password.length>25) {
                $('#password_status').text('Too long');
            }else if (password.length<6) {
                $('#password_status').text('Too short');
            }else{
                $.post('php/register.php', { password: password }, function(data) {
                    //do you really need to check this, other then when inserting to DB ?
                    $('#password_status').text(data); 
                });
            }
        }else{
            $('#password_status').text('');
        }
    });
    
    $('#username').on('keyup', function() {
        var username = this.value;
        if (username != '') {
            $('#username_status').text('Searching...');
            if (username.length>25) {
                $('#username_status').text('Too long'); 
            }else if (username.length<6) {
                $('#username_status').text('Too short'); 
            }else{
                $.post('php/register.php', { username: username }, function(data) {
                    $('#username_status').text(data);
                });
        }else{
            $('#username_status').text('');
        }
    });
    

    PHP

    <?php
        include '../connect/userdb_connect.php';
    
        if (isset($_POST['password'])) {
            $password = mysql_real_escape_string($_POST['password']);
            if (!empty($password) && strlen($password)<25 && strlen($password)>6) {
                //hash and insert into db
            }else{
                //error
            }
        }else{
           //no POST var
        }
    
        if (isset($_POST['username'])) {
            $username = mysql_real_escape_string($_POST['username']);
            if (!empty($username) && strlen($username)<25 && strlen($username)>6) {
                $check = mysql_query("SELECT `user_name` FROM `userbase` WHERE `user_name`  = '$username'");
                $result = mysql_num_rows($check);
                if ($result == 0) {
                    echo 'Available';
                }else if ($result == 1) {
                    echo 'Already taken';
                }
            }else{
                //error
            }
        }else{
           //no POST var
        }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small issue on a search form. PLease check this: http://www.fortisfitness.ca/test/script.php What's
I have two function, one function is a reload function that does a ajax
I have a pretty common layout issue that I have traditionally used a table
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So
My issue is that I have created a table for a local db in
Having an issue here that I have tried everything I can think of but
I'm running into an issue in that I have a document indexed with elasticsearch
I have an issue that seems like very flaky behavour, is this a problem
I have an issue that looks like a race condition with a webview callback
I have a strange issue that has arisen recently: Whenever I enter text, even

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.