Javascript PHP,检查表上的数据库中是否存在用户?

Javascript PHP,检查表上的数据库中是否存在用户?,javascript,php,html,mysql,sql,Javascript,Php,Html,Mysql,Sql,我试图检查var a=document.forms[“reg”][“matricula”].value存在于我的数据库中,但是用户将把这个值放在camp上 如何检查数据库中是否存在var“a” function validateForm() { var a=document.forms["reg"]["matricula"].value; var b=document.forms["reg"]["nome"].value; var c=document.forms["reg"]["cargo"]

我试图检查
var a=document.forms[“reg”][“matricula”].value存在于我的数据库中,但是用户将把这个值放在camp上

如何检查数据库中是否存在var“a”

function validateForm()
{
var a=document.forms["reg"]["matricula"].value;
var b=document.forms["reg"]["nome"].value;
var c=document.forms["reg"]["cargo"].value;

if ((a==null || a=="") && (b==null || b=="") && (c==null || c==""))
  {
  alert("Todos os campos devem ser preenchidos!");
  return false;
  }

if (a==null || a=="")
  {
  alert("A matrícula deve ser preenchida!");
  return false;
  }
if (b==null || b=="")
  {
  alert("O nome deve ser preenchido!");
  return false;
  }
if (c==null || c=="")
  {
  alert("O cargo deve ser selecionado!");
  return false;
  }
}
如何检查数据库中是否存在var“a”

function validateForm()
{
var a=document.forms["reg"]["matricula"].value;
var b=document.forms["reg"]["nome"].value;
var c=document.forms["reg"]["cargo"].value;

if ((a==null || a=="") && (b==null || b=="") && (c==null || c==""))
  {
  alert("Todos os campos devem ser preenchidos!");
  return false;
  }

if (a==null || a=="")
  {
  alert("A matrícula deve ser preenchida!");
  return false;
  }
if (b==null || b=="")
  {
  alert("O nome deve ser preenchido!");
  return false;
  }
if (c==null || c=="")
  {
  alert("O cargo deve ser selecionado!");
  return false;
  }
}
实现这一目标的方法有很多

对于您的情况,因为您正在标记javascript。 验证表单后,将表单值发送到单独的查询并返回到同一页面。在本例中,查询结果将返回到警报框

function validateForm() {
//.......if(...) form validation starts....

    if (c==null || c=="") {
        alert("O cargo deve ser selecionado!");
        return false;
    }

//Submit matricula and or other value to query page and return result to an alert box example
    var xhttp = new XMLHttpRequest();
    var querypage = "yourquerypagelocation.php";
    var form = document.getElementById("reg");
    var formData = new FormData(form);
    xhttp.onreadystatechange = function() {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
            alert(xhttp.responseText);//<- this will open a alert box with your query response
            }
        }
    xhttp.open("POST",querypage,true);
    xhttp.send(formData);
}
函数validateForm(){
//…如果(…)表单验证开始。。。。
如果(c==null | | c==“”){
警报(“哦,货物运输公司!”;
返回false;
}
//将矩阵和/或其他值提交到查询页面,并将结果返回到警报框示例
var xhttp=newXMLHttpRequest();
var querypage=“yourquerypage.php”;
var form=document.getElementById(“reg”);
var formData=新formData(表格);
xhttp.onreadystatechange=函数(){
如果(xhttp.readyState==4&&xhttp.status==200){

alert(xhttp.responseText);//使用select查询?创建一个单独的php文件,将您的php代码放在那里,然后通过ajax从您的js中提取该页面值。@Dagon,是的!一个查询well-um-write-one?您在问我们什么?