Warm tip: This article is reproduced from stackoverflow.com, please click
html jquery php

how to check username and email already exist except for one particular id in database using jquery

发布于 2020-03-31 22:54:15

I want to check whether the username and email is already exist in edit page.. So need to check it except for that particular if.. How is it possible using jquery validator..

I have tried with following format :

Jquery :

<script>
    $(document).ready(function(){         
        $("#frmForm").validate({
            rules: {                
                empemail: {
                           required: true,
                           remote: "../admin/checkEmail.php?data=email"
                },
                username: {
                           required: true,
                           remote: "../admin/checkEmail.php?data=name"
                },              
            },
            messages: {             
                username: {
                               required:"*",
                               remote: "already exists"
                            },
                empemail: {
                               required:"*",
                               remote: "already exists"
                            },              
                }
        });   
    });
</script>

HTML page

<form  method="post" action="updateEmp.php" id="frmForm">
    <label >Email </label>
    <input type="email" name="empemail" value="<?php echo $row['email'] ?>">    
    <label >Username</label>
    <input type="text" name="username" value="<?php echo $row['username'] ?>">                          
    <button class="btn btn-primary btn-sm" type="submit" >Update</button>
</form>
Questioner
Micku
Viewed
21
user2732844 2015-09-16 13:27

Pass that particular id in your remote url like remote: "../admin/checkEmail.php?data=email&id=23" say your particular id be 23

and in your checkEmail.php you can write query like

"SELECT email FROM table_name WHERE email='".$_GET['email']."' AND id!='".$_GET['id']."'"

same way you can do for username also