php - Validation display name using jQuery remote method -


i've tried added remote method check display name if has exists.

email validation can check , display messages if email has exists display name validation not work. what's wrong code?

my code

register.php

<?php require_once 'config.php'; ?> <?php      if(!empty($_post)){         try {             $user_obj = new cl_user();             $data = $user_obj->registration( $_post );             if($data)$success = user_registration_success;         } catch (exception $e) {             $error = $e->getmessage();         }     } ?> <!doctype html> <html lang="en">   <head>     <meta charset="utf-8">     <meta http-equiv="x-ua-compatible" content="ie=edge">     <meta name="viewport" content="width=device-width, initial-scale=1">     <title>smart registration form</title>     <!-- bootstrap -->     <link href="css/bootstrap.min.css" rel="stylesheet">     <link href="css/font-awesome.min.css" rel="stylesheet">     <link href="css/login.css" rel="stylesheet">      <!-- html5 shim , respond.js ie8 support of html5 elements , media queries -->     <!-- warning: respond.js doesn't work if view page via file:// -->     <!--[if lt ie 9]>       <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>       <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>     <![endif]-->      <!-- jquery (necessary bootstrap's javascript plugins) -->     <script src="js/jquery.min.js"></script>     <!-- include compiled plugins (below), or include individual files needed -->     <script src="js/bootstrap.min.js"></script>   </head>   <body>     <div class="container">         <div class="login-form">             <?php require_once 'templates/message.php';?>              <h1 class="text-center">smart tutorials</h1>             <div class="form-header">                 <i class="fa fa-user"></i>             </div>             <form method="post" action="<?php echo $_server['php_self']; ?>" class="form-register" role="form" id="register-form">                 <div>                     <input name="name" id="name" type="text" class="form-control" placeholder="dispaly name">                      <span class="help-block"></span>                 </div>                 <div>                     <input name="email" id="email" type="email" class="form-control" placeholder="email address" >                      <span class="help-block"></span>                 </div>                 <div>                     <input name="password" id="password" type="password" class="form-control" placeholder="password">                      <span class="help-block"></span>                 </div>                 <div>                     <input name="confirm_password" id="confirm_password" type="password" class="form-control" placeholder="confirm password">                      <span class="help-block"></span>                 </div>                 <button class="btn btn-block bt-login" type="submit" id="submit_btn" data-loading-text="signing up....">sign up</button>             </form>             <div class="form-footer">                 <div class="row">                     <div class="col-xs-6 col-sm-6 col-md-6">                         <i class="fa fa-lock"></i>                         <a href="forget_password.php"> forgot password? </a>                      </div>                      <div class="col-xs-6 col-sm-6 col-md-6">                         <i class="fa fa-check"></i>                         <a href="index.php"> sign in </a>                     </div>                 </div>             </div>         </div>     </div>     <!-- /container -->       <script src="js/jquery.validate.min.js"></script>     <script src="js/register.js"></script>   </body> </html> 

register.js

$(document).ready(function(){      $("#register-form").validate({         submithandler : function(form) {             $('#submit_btn').attr('disabled','disabled');             $('#submit_btn').button('loading');             form.submit();         },         rules : {             name : {                 required : true,                 name: true,                 remote: {                     url: "check-name.php",                     type: "post",                     data: {                       name: function() {                         return $( "#name" ).val();                       }                     }                   }             },             email : {                 required : true,                 email: true,                 remote: {                     url: "check-email.php",                     type: "post",                     data: {                         email: function() {                             return $( "#email" ).val();                         }                     }                 }             },             password : {                 required : true             },             confirm_password : {                 required : true,                 equalto: "#password"             }         },         messages : {             name : {                 required : "please enter name",                 remote : "diaplay name exists"             },             email : {                 required : "please enter email",                 remote : "email exists"             },             password : {                 required : "please enter password"             },             confirm_password : {                 required : "please enter confirm password",                 equalto: "password , confirm password doesn't match"             }         },         errorplacement : function(error, element) {             $(element).closest('div').find('.help-block').html(error.html());         },         highlight : function(element) {             $(element).closest('div').removeclass('has-success').addclass('has-error');         },         unhighlight: function(element, errorclass, validclass) {              $(element).closest('div').removeclass('has-error').addclass('has-success');              $(element).closest('div').find('.help-block').html('');         }     });   }); 

check-name.php

<?php require_once 'config.php'; $db = new cl_dbclass(); if( isset( $_post['name'] ) && !empty($_post['name'])){     $name = $_post['name'];     $query = " select count(name) cnt users name = '$name' ";     $result = mysqli_query($db->con, $query);     $data = mysqli_fetch_assoc($result);     if($data['cnt'] > 0){         echo 'false';     }else{         echo 'true';     }     exit; } ?> 

edit

check-email.php

<?php require_once 'config.php'; $db = new cl_dbclass();  if( isset( $_post['password'] ) && !empty($_post['password'])){     $password =md5( trim( $_post['password'] ) );     $email = $_post['email'];      if( !empty( $email) && !empty($password) ){         $query = " select count(email) cnt users password = '$password' , email = '$email' ";         $result = mysqli_query($db->con, $query);         $data = mysqli_fetch_assoc($result);         if($data['cnt'] == 1){             echo 'true';         }else{             echo 'false';         }     }else{         echo 'false';     }     exit; }  if( isset( $_post['email'] ) && !empty($_post['email'])){     $email = $_post['email'];     $query = " select count(email) cnt users email = '$email' ";     $result = mysqli_query($db->con, $query);     $data = mysqli_fetch_assoc($result);     if($data['cnt'] > 0){         echo 'false';     }else{         echo 'true';     }     exit; } ?> 


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -