Регистрационная форма продолжает запрашивать ошибку

Код на странице регистрации может работать ранее, но после "function submitForm()"в jquery. и я начинаю запускать форму регистрации, она будет держать вспышку со значком на:

Эхо » 1″
Введите описание изображения здесь

здесь php код на моем регистре.РНР

<?php

$_POST = array(); //workaround for broken PHPstorm
parse_str(file_get_contents('php://input'), $_POST);

    require_once 'dbConn.php';

    $message='';

    if($_POST)
    {
        $user_nric = $_POST['nric'];
        $user_name = $_POST['name'];
        $user_email = $_POST['email'];
        $user_password = $_POST['password'];
        $user_gender = isset($_POST['gender']) ? $_POST['gender'] : '';
        $user_role = isset($_POST['role']) ? $_POST['role'] : '';

        $password = md5($user_password);

        try
        {
            $stmt = $conn->prepare("SELECT * FROM `user` WHERE nric=:nric");
            $stmt->execute(array(":nric"=>$user_nric));
            $count = $stmt->rowCount();

            if($count==0){

            $stmt = $conn->prepare("INSERT INTO user(nric,name,email,password,gender,role) VALUES(:nric, :name, :email, :password, :gender, :role)");
            $stmt->bindParam(":nric",$user_nric);
            $stmt->bindParam(":name",$user_name);
            $stmt->bindParam(":email",$user_email);
            $stmt->bindParam(":gender",$user_gender);
            $stmt->bindParam(":role",$user_role);
            $stmt->bindParam(":password",$password);
            //$stmt->bindParam(":jdate",$joining_date);

                if($stmt->execute())
                {
                    echo "registered";
                }
                else
                {
                    echo "Query could not execute !";
                }

            }
            else{

                echo "1"; //  not available
            }

        }
        catch(PDOException $e){
            echo $e->getMessage();
        }
    }

?>

здесь регистр jquery:

$('document').ready(function()
{
     /* validation */
     $("#register-form").validate({
      rules:
      {
            nric: {
            required: true,
            minlength: 9,
            maxlength: 9,
            nowhitespace: true
            },
            name: {
            required: true,
            minlength: 3,
            maxlength: 20,
            lettersonly: true
            },
            password: {
            required: true,
            minlength: 8,
            maxlength: 15
            },
            cpassword: {
            required: true,
            equalTo: '#password'
            },
            email: {
            required: true,
            email: true
            },
            gender: {
                required: function() {
                    return $('[name="gender"]:checked').length;
                }
            },
            role: {
                required: function() {
                    return $('[name="role"]:checked').length;
                }
            }
       },
       messages:
       {
            nric:{
                required: "Please enter the valid nric",
                minlength: "NRIC should be more than 9 characters",
                maxlength: "NRIC should be less than 9 characters",
                nowhitespace: "NRIC should not have any spaces"
            },
            name: {
                required: "please enter user name",
                minlength: "Name should be more than 3 character",
                maxlength: "Name should be less than 20 character",
                lettersonly: "Name should contain only letter"
            },
            password:{
                      required: "please provide a password",
                      minlength: "password at least have 8 characters"
                     },
            email: "please enter a valid email address",
            cpassword:{
                        required: "please retype your password",
                        equalTo: "password doesn't match !"
                      },
            gender: {
                required: "Select a gender"
            },
            role: {
                required: "Select a role"
            }
       },
       submitHandler: submitForm()
       });  
       /* validation */


       /* form submit */
       function submitForm()
       {        
                var data = $("#register-form").serialize();

                $.ajax({

                type : 'POST',
                url  : 'register.php',
                data : data,
                beforeSend: function()
                {   
                    $("#error").fadeOut();
                    $("#btn-submit").html('<span class="glyphicon glyphicon-transfer"></span> &nbsp; sending ...');
                },
                success :  function(data)
                           {                        
                                if(data==1){

                                    $("#error").fadeIn(1000, function(){


                                            $("#error").html('<div class="alert alert-danger"> <span class="glyphicon glyphicon-info-sign"></span> &nbsp; Sorry nric already taken !</div>');

                                            $("#btn-submit").html('<span class="glyphicon glyphicon-log-in"></span> &nbsp; Create Account');

                                    });

                                }
                                else if(data=="registered")
                                {

                                    $("#btn-submit").html('<img src="../images/btn-ajax-loader.gif" /> &nbsp; Signing Up ...');
                                    setTimeout('$(".form-signin").fadeOut(500, function(){ $(".signin-form").load("register-success.php"); }); ',5000);

                                }
                                else{

                                    $("#error").fadeIn(1000, function(){

                        $("#error").html('<div class="alert alert-danger"><span class="glyphicon glyphicon-info-sign"></span> &nbsp; '+data+' !</div>');

                                    $("#btn-submit").html('<span class="glyphicon glyphicon-log-in"></span> &nbsp; Create Account');

                                    });

                                }
                           }
                });
                return false;
        }
       /* form submit */

});

2 ответа

  1. если nric уже существует в Table user, то echo 1, поскольку $ count не равен нулю. см. следующий код:

       if($count==0){
    
            $stmt = $conn->prepare("INSERT INTO user(nric,name,email,password,gender,role) VALUES(:nric, :name, :email, :password, :gender, :role)");
            $stmt->bindParam(":nric",$user_nric);
            $stmt->bindParam(":name",$user_name);
            $stmt->bindParam(":email",$user_email);
            $stmt->bindParam(":gender",$user_gender);
            $stmt->bindParam(":role",$user_role);
            $stmt->bindParam(":password",$password);
            //$stmt->bindParam(":jdate",$joining_date);
    
                if($stmt->execute())
                {
                    echo "registered";
                }
                else
                {
                    echo "Query could not execute !";
                }
    
            }
            else{
    
                echo "1"; //  not available
            }
    
  2. удалить echo » 1 » отсюда:

    else{
    
            echo "1"; //  not available
    

    и пожалуйста ответьте что оно делает.