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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:20:18+00:00 2026-05-22T01:20:18+00:00

This is pretty specific and I have not found an answer yet. I am

  • 0

This is pretty specific and I have not found an answer yet.
I am writing a script to check if a name is already input into the SQL server using JQuery $.POST.

The front end looks like this:

register.php

<div id="container" class="container">
    <div id="wrapper" class="wrapper">
        <div id="title" class="title">
            Welcome to Taskar!
        </div>
        <div id="login" class="login">
            <form method="post" action="registermembers.php">
            <div id="exists">
                Register Your Company Below:
            </div>
            <input type="text" id="company" name="company" value="Company Name"/> <br />
            <br />
            <input type="text" id="password" name="password" value="Default Password"/> <br />
            <input type="submit" name="submitcompany" value="Submit" />
            </form>

            <script>
            $(document).ready(function() {
                $('#company').keyup(function() {
                    var $company = $(this).val();
                    var $reg = $('#exists').html();
                    $.post('include/reg_post.php', { company: $company, reg: $reg }, function(company) {
                    $('#exists').html(company);
                    });
                });
            });
            </script>

        </div>
    </div>
</div>

The backend code looks like this:

reg_post.php

<?php
include 'include/db.php';

$reg = $_POST['reg'];
$company = $_POST['company'];
$email_hash = $_COOKIE['email_hash'];
$password = $_COOKIE['password'];

$sql = "SELECT * FROM taskar_employee WHERE (company = '$company')";
$result = mysql_query($sql) or die(mysql_error());
    if(mysql_num_rows($result) <= 1){
        echo $reg;
    } else {
        echo "This Company Already Exists!";
    } ?>

Now, the problem I am having is, when I am testing this, it works fine all the way up to when I type in a company name that is in the database. It shows me that the company is already registered. When I press backspace or type another letter, it still tells me the company still exists, though it obviously would not.

It seems that the if statement wants to stop the $.post feature from continuing after it gets the opposite statement?

What do you guys think?

  • 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-05-22T01:20:19+00:00Added an answer on May 22, 2026 at 1:20 am

    Your problem lies in the way you’re using your $reg variable.

    $reg contains the HTML contents of the #exists div, so it’s “Register your Company Below:” to begin with. But, once you’ve hit a company name that does exist, you replace that HTML with “This Company Already Exists!”. From that point on, $reg, on both the JavaScript and PHP sides, is always “This Company Already Exists!” (since you always pass $reg in your POST).

    It would probably be much easier if the contents of that div weren’t passed to or handled by the PHP code at all. It’d be simpler if your PHP script just returned “1” if the company existed, and “0” if not (or some other equally simple flags).

    Then, on the JavaScript side, you could just do:

    $.post('include/reg_post.php', { company: $company }, function(exists) {
        var message;
        if (exists === '1') {
            message = 'This Company Already Exists!';
        }
        else {
            message = 'Register Your Company Below:';
        }
        $('#exists').html(message);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've not found anything that addresses my specific name space question as yet. I
So this is pretty specific to a website I am working on. I have
first I have to admit this might be a pretty specific problem. In a
I have written something like this pretty easily in C# ( string GetUrl(new {
This is pretty much the same problem i have, except with very different code:
I've looked for this question on stackoverflow, but didn't found a really good answer
Search as I may I have not found a solution to my problem here
I know this is a pretty specific question but I managed to get some
this pretty much is the thing. When in tinymce I press anything that is
I find this pretty confusing. When you want to rotate a view, it's going

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.