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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:56:42+00:00 2026-05-26T15:56:42+00:00

Using ajax+php in my signup form. There are 2 validations: JS side frontend and

  • 0

Using ajax+php in my signup form. There are 2 validations: JS side frontend and PHP side backend. Created special function called response in PHP side: It sends PHP side error as JSON data.

The problem is I can’t get any response from PHP side.

Analyzed page in firebug: getting error message responseData is null. (responseData = jQuery.parseJSON(data))

JS part looks like that

  //check the form is not currently submitting
  if ($(this).data('formstatus') !== 'submitting') {

 var form = $(this),
    formData = form.serialize() + '&formID=' + form.attr('id'),
    formUrl = form.attr('action'),
    formMethod = form.attr('method');



 //add status data to form
 form.data('formstatus', 'submitting');

 if (validate()) {
    //send data to server for validation
    $.ajax({
       url: formUrl,
       type: formMethod,
       data: formData,
       success: function (data) {

          //setup variables
          var responseData = jQuery.parseJSON(data),
             cl, text;

          //response conditional
          switch (responseData.status) {
          case 'error':
             cl = 'error';
             text = responseData.message;
             break;
          case 'success':
             cl = 'success';
             text = 'Qeydiyyat uğurla başa çatdı';
             break;
          }


          $.notifyBar({
             cls: cl,
             html: text
          });

       }
    });

 }
 form.data('formstatus', 'idle');


 }

And here is PHP part

    <?php
require '../common.php';

function checkIfEmailExists($email, $stmt)
{
        if ($stmt = $db->prepare("SELECT id FROM TABLE WHERE email=? LIMIT 1")) {
                $stmt->bind_param("s", $email);
                $stmt->execute();
                $stmt->bind_result($count);
                $stmt->close();
        }

        return ($count > 0 ? true : false);
}


if ($_POST['formID'] == 'signup_form') {
        // Setting vars
        $lname        = $_POST['lname'];
        $fname        = $_POST['fname'];
        $mname        = $_POST['mname'];
        $email        = $_POST['email'];
        $pass         = $_POST['pass'];
        $confirm_pass = $_POST['confirm_pass'];

        //===================== 
        //Server side validation >>


        //First name, middle name, last name check >>
        if (!$lname) {
                response('error', 'Familiyanı daxil edin');
        }
        if (!$fname) {
                response('error', 'Adı daxil edin');
        }
        if (!$mname) {
                response('error', 'Atanızın adını daxil edin');
        }
        //<<

        //Pass check >>
        if (strlen($pass) > 2) {
                if ($pass == $confirm_pass) {
                        return true;
                } else {
                        response('error', 'Şifrənin təkrarlanmasında səhv');
                }
        } else {
                response('error', 'Şifrədə simvolların sayı 4-dən çox olmalıdır');
        }

        //<<


        //email validation >>
        if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
                if (!checkIfEmailExists($email, $stmt)) {
                        return true;
                } else {
                        response('error', 'Bu ünvanla qeydiyyata alınmış başqa istifadəçi var.');
                }
        } else {
                response('error', 'Email ünvanını düzgün daxil edin');
        }

        //<<

        // Create statement object
        $stmt = $db->stmt_init();

        // Create a prepared statement
        if ($stmt->prepare("INSERT INTO `users` (`fname`, `mname`, `lname`, `email`, `pass`, `reg_dt`) VALUES (?, ?, ?, ?, ?, NOW())")) {
                // Binding vars

                $rc = $stmt->bind_param('sssss', $fname, $lname, $mname, $email, $pass) or die('bind_param() failed: ' . htmlspecialchars($stmt->error));

                // Execute query
                $rc = $stmt->execute();
                if ($rc) {
                        response('success', 'Qeydiyyat uğurla başa çatdı');
                } else {
                        response('error', htmlspecialchars($stmt->error));
                }


                // Close statement object
                $stmt->close();

        } else {
                response('error', htmlspecialchars($dv->error));
        }



}
else {response('error', 'Qeydiyyatda problem');}

        //return json response
        function response($status, $message)
        {
                $data = array(
                        'status' => $status,
                        'message' => $message
                );
                echo json_encode($data);
                die();
        }
?>
  • 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-26T15:56:42+00:00Added an answer on May 26, 2026 at 3:56 pm

    You need to add

    dataType: "json",
    

    In your $.Ajax method.

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

Sidebar

Related Questions

I've created an ajax sign up form using jquery to a PHP backend. My
I have created an form validation using ajax/php. Each text box is validated using
I'm posting data using jquery/ajax and PHP at the backend. Problem being, when I
I'm using the JQuery AJAX function to deliver data to a PHP doc. Currently,
With a function a div-popover gets called and filled with dynamic data using Ajax,
I am trying to fill in a form using Javascript/ajax/php but the problem is
How to count values of two drop down using ajax or php Example Form
I am using php/ajax to submit a form without page refresh. Here are my
I am using jQuery and Ajax, and my Ajax.php file returns the following field
I am using jQuery, JavaScript and PHP. My Ajax.php file just displays the 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.