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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:46:38+00:00 2026-06-02T20:46:38+00:00

Here is the form to have ajax check out user existence. <!DOCTYPE html> <html>

  • 0

Here is the form to have ajax check out user existence.

<!DOCTYPE html>

<html>
    <head><title>Register new user!</title>
    <script src="jquery-1.7.1.min.js"></script>
    </head>
    <body>
        Username:
        <input type="text" name="username" id="username"/><span id="user"></span><br/>
        Password:
        <input type="password" name="password" id="password"/><br/>
        <input type="button" value="Register" name="submit" id="submit" onclick="register_user();"/>
    </body>
    <script>
        function register_user()
        {
            $.ajax(
                {
                    type:"POST",
                    data:username,
                    url:"userexists.php"                    
                })
            .fail(function()
                  {
                    $('#user').html("This user already exists");
                  }
            );                
        }
    </script>
</html>

And here is the userexists.php module

<?php
    // connection to the db
    define(IPHOST,"localhost");
    define(DBPASSWORD,"");
    define(DBUSER,"root");
    define(DATABASE,"ajaxtest");
    define(TABLENAME,"at");

    $conn=mysql_connect(IPHOST,DBUSER,DBPASSWORD) or die(mysql_error());
    mysql_select_db(DATABASE) or die(mysql_error());
    $username=$_POST('username');
    $sql="SELECT username FROM ".TABLENAME." WHERE username=".$username;
    $query=mysql_query($sql);
    if(0!=mysql_numrows($query))
    {
        //
    }
    else
    {

    }
?>

But I am stuck to really figure out how the ajax function actually works, what should I enter the blank field after I know that the entered username has been used, for example ? I don’t understand ajax at all.

[UPDATE]
Thank you, I understand it now, I have got several answers, don’t know which one to choose as the best reply. No option to choose 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-02T20:46:41+00:00Added an answer on June 2, 2026 at 8:46 pm

    You have a lot of mistakes in your code, try codes below:

    <!DOCTYPE html>
    
    <html>
        <head><title>Register new user!</title>
        <script src="jquery-1.7.1.min.js"></script>
        </head>
        <body>
            Username:
            <input type="text" name="username" id="username"/><span id="user"></span><br/>
            Password:
            <input type="password" name="password" id="password"/><br/>
            <input type="button" value="Register" name="submit" id="submit" onclick="register_user();"/>
        </body>
        <script>
            function register_user()
            {
                $.ajax({
                    type: "POST",
                    data: {
                        username: $('#username').val(),
                    },
                    url: "userexists.php",
                    success: function(data)
                    {
                        if(data === 'USER_EXISTS')
                        {
                            $('#user')
                                .css('color', 'red')
                                .html("This user already exists!");
                        }
                        else if(data === 'USER_AVAILABLE')
                        {
                            $('#user')
                                .css('color', 'green')
                                .html("User available.");
                        }
                    }
                })              
            }
        </script>
    </html>
    

    And for your php code:

    <?php
        // connection to the db
        define(IPHOST,"localhost");
        define(DBPASSWORD,"");
        define(DBUSER,"root");
        define(DATABASE,"ajaxtest");
        define(TABLENAME,"at");
    
        $conn=mysql_connect(IPHOST,DBUSER,DBPASSWORD) or die(mysql_error());
        mysql_select_db(DATABASE) or die(mysql_error());
    
        $username = mysql_real_escape_string($_POST['username']); // $_POST is an array (not a function)
        // mysql_real_escape_string is to prevent sql injection
    
        $sql = "SELECT username FROM ".TABLENAME." WHERE username='".$username."'"; // Username must enclosed in two quotations
    
        $query = mysql_query($sql);
    
        if(mysql_num_rows($query) == 0)
        {
            echo('USER_AVAILABLE');
        }
        else
        {
            echo('USER_EXISTS');
        }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Ajax script that allows me to check a form without refreshing
I have this form right here, where the user will add the start date
I have ajax domain lookup script. Look here for DEMO: Here is JS code
Here is what I have... function checkDB(code, userid) { $(#notice_div).html('Loading..'); $.ajax({ type: POST, url:
I have few buttons that call Ajax functions (submit contact form, submit newsletter, check
so here's the problem I have one form, it outputs search results after submit,
We currently have a form with the standard multi-select functionality of here are the
I have this form in my view: <!-- Bug (extra 'i') right here-----------v -->
i have the form, and i want to upload two files. here is the
Here I have a password field: /*********************PASSWORD**********************/ $password = new Zend_Form_Element_Password('password'); $alnumValidator = new

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.