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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:26:44+00:00 2026-05-13T07:26:44+00:00

i have a jquery ajax form. i have validation at server side for repeated

  • 0

i have a jquery ajax form.
i have validation at server side for repeated username and email ID.
which works fine without jquery/ajax.

in my php code i have used die() to return if any error occurs. my main problem is at ajax

here is the code

$(document).ready(function () {

    $("form#regist").submit(function () {
        var str = $("#regist").serialize();
        $.ajax({
            type: "POST",
            url: "submit1.php",
            data: $("#regist").serialize(),
            success: function () {

                $("#loading").append("<h2>you are here</h2>");

            }

        });
        return false;


    });
});

The success function works properly. if my data is valid then it is added in the db, if my data is repeated then it is not added in the db. Now what i want to know is how do i return the error from my php file and use it at success event. Thanks in advance..

edit : this is how my php script looks

$query = "SELECT username from userdetails WHERE username = '$username'";
$q = mysql_query($query) or die("error" . mysql_error());
$numrows = mysql_num_rows($q);
if($numrows > 0)
{
die("username already exixt");
//should i put something like this
//$error = "username already exists";
//return $error; --->> i am not sure about this..
}

thanks in advance

  • 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-13T07:26:44+00:00Added an answer on May 13, 2026 at 7:26 am

    Php side:

    if($numrows > 0)
    {
    echo "username already exist";
    }
    

    Javascript side:

    success: function(msg)
      {
       if(msg == 'username already exist') alert(msg);
      }
    

    But this is so crude, If you plan to develop this further try to read some articles on JSON, so you can use json to communicate to server side. And also you should try to use some default error controlling, like return an array with php:

    echo json_encode(array('error' => true, 'notice' => 'username exists'));
    

    Then on the javascript side (jquery), use json ajax request and always check if error variable is true or not, if it is maybe you can use a default function for error controlling.

    Hope this helped.

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

Sidebar

Ask A Question

Stats

  • Questions 267k
  • Answers 267k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer MvcContrib has it: http://mvccontrib.codeplex.com/wikipage?title=RedirectToAction May 13, 2026 at 12:55 pm
  • Editorial Team
    Editorial Team added an answer According to RegexBuddy use this as your regex \b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[A-Z0-9+&@#/%=~_|] and… May 13, 2026 at 12:55 pm
  • Editorial Team
    Editorial Team added an answer I recently stumbled upon this awesome feature of Django and… May 13, 2026 at 12:55 pm

Related Questions

Ok, so here's the situation. I'm working on a site that allows people to
The Situation I have a very compressed time schedule to write a simple (basically
I have been using the JEditable plugin for JQuery and I would like to
I have the following form in cakephp: <div class=quickcontactDisplay> <?php echo $form->create('Enquiry',array('action'=>'add','class'=>'quickcontact')); echo $form->hidden('visitor_id',
I have a form (signup.php) that pops up in a nyroModal window when I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.