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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:07:02+00:00 2026-06-08T23:07:02+00:00

returning multiple errors in the ajax response is proving troublesome, if multiple errors are

  • 0

returning multiple errors in the ajax response is proving troublesome, if multiple errors are echoed, 1&2 for example becomes 12. What would be the best way to return the response data, in an array? Any help is much appreciated, thanks in advance.

This is the function for POSTING the form to the PHP validator

$("document").ready(function() {
    $("#btn-signup").click(function() {
        var first_name = $("#fname_up").val();
        var last_name = $("#lname_up").val();
        var vemail = $("#email_up").val();
        var password = $("#password_up").val();
        var cpassword = $("#cpassword_up").val();
        var dataString = 'firstname='+first_name+'&lastname='+last_name+'&email='+vemail+'&password='+password+'&cpassword='+cpassword;
        $.ajax({
            type: "POST",
            url: "-signup.php",
            data: dataString,
            success: function(response){
                if (response == 1) {
                    console.log("1");
                }
                if (response == 2) {
                    console.log("2");
                }
                if (response == 3) {
                    console.log("3");
                }
                if (response == 4) {
                    console.log("4");
                }
                if (response == 5) {
                    console.log("5");
                }
                if (response == 6) {
                    console.log("6");
                }
                if (response == 7) {
                    console.log("7");
                }
                if (response == 12) {
                    console.log("You got to here");
                }
            }
        });
    return false;
    });
});

This is the PHP form validator.

<?php

session_start();
require_once "database.php";
db_connect();

$errors = array();

// If request is a form submission
if($_SERVER['REQUEST_METHOD'] == 'POST'){
  // Validation

  // Check first_name is non-blank
  if(0 === preg_match("/\S+/", $_POST['firstname'])){
    echo "1";
  }

  // Check last_name is non-blank
  if(0 === preg_match("/\S+/", $_POST['lastname'])){
    echo "2";
  }

  // Check email is valid (enough)
  if(0 === preg_match("/.+@.+\..+/", $_POST['email'])){
    echo "3";
  }

  // Check password is valid
  if(0 === preg_match("/.{6,}/", $_POST['password'])){
    echo "4";
  }

  // Check password confirmation_matches
  if(0 !== strcmp($_POST['password'], $_POST['cpassword'])){
    echo "5";
  }

  // If no validation errors
  if(0 === count($errors)){

    // Sanitize first, last, and email
    $firstname = mysql_real_escape_string($_POST['firstname']);
    $lastname  = mysql_real_escape_string($_POST['lastname']);
    $email      = mysql_real_escape_string($_POST['email']);
    $password      = mysql_real_escape_string($_POST['password']);
    $cpassword     = mysql_real_escape_string($_POST['cpassword']);

    // Generate pseudo-random salt
    $salt = sha1(microtime() . $_POST['password']);

    // Generate password from salt
    $password = sha1($salt . $_POST['password']);


    // Insert user into the database
    $query = "INSERT INTO.......

    $result = mysql_query($query);

    if(mysql_errno() === 0){
      // Registration successful
      $user_id = mysql_insert_id();
      log_in($user_id);
      echo "9";
    } else if (preg_match("/^Duplicate.*email.*/// get rid of the two lines beforei", mysql_error())){
      echo "10";
    }  
  }
}
  • 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-08T23:07:04+00:00Added an answer on June 8, 2026 at 11:07 pm

    Which are the errors you get? Is your AJAX URL correctly assigned?

    I think you should give the absolute path to the “-signup.php” file. Something like /path/to/signup-file.php

    Why did you used if(0 === count($errors)) and not if(count($errors) == 0), also for the above verifications. You can use if(empty($errors)).

    For more help please write us the errors you have

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

Sidebar

Related Questions

Possible Duplicate: returning multiple values from a function For example if you want a
Our WordPress 2.8.6 installation is returning multiple different errors when trying to edit theme
I have a query returning multiple values associated with one thing. For example, if
I'm having some trouble returning multiple values in this program that calculates min, max,
i dont understand the problem with returning multiple rows: here is my table BBC:
Are there any idioms for returning multiple values from a bash function within a
A SDK is returning me an array with multiple dimensions such as: int[,,] theArray
I am trying to get my query to grab multiple rows while returning the
I would like to create a UIView has multiple UITextFields validates each one as
i Have a problem returning multiple rows in one output there are multiple user_roleID's

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.