温馨提示:本文翻译自stackoverflow.com,查看原文请点击:jquery - how to check username and email already exist except for one particular id in database using jquery
html jquery php

jquery - 如何使用jQuery查询指定ID用户名和电子邮件是否已经存在?

发布于 2020-03-31 23:11:25

我想检查用户名和电子邮件是否已经存在于编辑页面中。因此需要检查该用户名和电子邮件地址(如果不是)。如何使用jquery验证程序。

我尝试了以下格式:

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页面

<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> 

查看更多

提问者
Micku
被浏览
13
user2732844 2015-09-16 13:27

在您的远程URL中传递该特定ID,例如remote: "../admin/checkEmail.php?data=email&id=23"说您的特定ID为23

在您的checkEmail.php中,您可以编写如下查询

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

您可以为用户名使用的相同方法