我想检查用户名和电子邮件是否已经存在于编辑页面中。所以需要检查它,除了特定的 if ..如何使用 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>
最佳答案
在你的远程 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']."'"
同样的方法你也可以为用户名做
关于php - 如何使用 jquery 验证器检查用户名和电子邮件已经存在,除了数据库中的一个特定 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32600169/