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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:24:57+00:00 2026-05-25T21:24:57+00:00

I am doing an AJAX post to a PHP processing script. I am checking

  • 0

I am doing an AJAX post to a PHP processing script. I am checking if MySQL returns any rows befoe proceeding with registration. The problem I’m having – MySQL quickly echoes 1 row and then echoes 0 and proceeds with registration, even if 0 rows exist. Why am I seeing 1 row returned, and then quickly correcting itself?

$.ajax({
            type: "POST",
            data: "username="+$(this).attr('username')+"password="+$(this).attr('email')+$(this).attr('password')+$(this).attr('passconf'),
            url: "includes/register.php",
            success: function(msg)
            {   
                alert(data);
                $("#result").data($data); 
            }
        });

    });

PHP code:

    $res = mysql_query("SELECT * FROM users WHERE username = '".$username."'");
                    if (!$res) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $query;
    die($message);
}
                    $num = mysql_num_rows($res);
                    echo $num;
  • 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-25T21:24:57+00:00Added an answer on May 25, 2026 at 9:24 pm

    Your event handler probably is failing to prevent the default action, causing the form to be submitted twice (once via ajax, and once via regular browser form submission). Try returning false like this:

    $(login_form).click(function() {
        $.ajax({ ... });
        return false;
    });
    

    Returning false prevents the default action and stops bubbling. In case you want bubbling to still apply, you can also explicitly prevent the default like this:

    $(login_form).click(function(ev) {
        ev.preventDefault();
        $.ajax({ ... });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing the following: <script type=text/javascript> $(function(){ $(#ipad).submit(function() { $.post(ipadcheck.php, $(#ipad).serialize(), function(data) {
In my document I have this script: $.ajax({ type:POST,url:ajax.php,data:data, success: function() { //onsuccess },
I'm doing a jQuery AJAX post like this: var form = $(#formid); form.submit(function() {
I am doing a simple $.ajax request: $.ajax({ type: POST, url: /Run/ + param1
I am doing an AJAX call that returns some HTML and jQuery: <div id='selected'>Here
I am having an issue with ajax sending values to my PHP script for
Hey guys, I'm doing an AJAX POST call - but with FireBug you can
$.ajax({ type: POST, url: check.php, data: checkit= + $(#checkEmail).val(), success: function(response){ $(#userCheck).html(response.status); if(response.status ==
I'm doing an ajax $.post to a node.js route which inserts into a mongodb
$.ajax({ type: POST, url: ajax.php, dataType: 'json', data: callback=bumpup_contact_us_entry&id= + id, success: function(data){ $.each(data,

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.