我现在真的很困惑,我对所有这些只是学习java脚本和php都很陌生。我正在尝试使用ajax检查数据库以查看电子邮件是否存在,然后是否取消提交表单。我似乎无法从XML中检索信息。我可能这样做完全错误的,但为什么我问这里,瘦ajax。从查询中检索信息
所以,如果你能帮助将是巨大的
JAVA SCRIPT
//validate the sign up/regiser form
function validateForm() {
//Get password varibles
var pass = document.forms["signup"]["sign-up-password"].value;
var confPass = document.forms["signup"]["password-confirm"].value;
//Check if they match
if (pass != confPass) {
alert("Password does not match");
return false;
}
//Ajax functions
if(xmlHttp.readyState==0 || xmlHttp.readyState==4){
alert("im here");
email = document.getElementById('email2').value;
xmlHttp.open("GET", "php/ajaxCom.php?email=" + email, true);
xmlHttp.onreadystatechange = handleServerResponse;
xmlHttp.send(null);
}else{
setTimeout('process()',1000);
}
}
function handleServerResponse(){
if(xmlHttp.readyState==4){
var check=xmlHttp.status;
if(xmlHttp.status==200){
alert("also here 2");
xmlResponse = xmlHttp.responseXML;
xmlDocumentElement = xmlResponse.documentElement;
message = xmlDocumentElement.firstChild.data;
alert(message);
return message;
}
}
}
php/xml
<?php
\t $status;
\t
if (isset($_GET['email'])) {
\t $email_in_use = $_GET['email'];
\t $query = mysqli_query($link, "SELECT * FROM users WHERE email='".$email_in_use."'");
\t if(mysqli_num_rows($query) > 0){
\t $status = false;
\t }else{
\t if(!mysqli_query($link, $query))
\t \t { $status = mysqli_error($link); }
\t \t else
\t \t { $status = true; }
\t }
\t $xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8" standalone="yes" ?><response><status/></response>');
\t $xml->response->status = $status;
\t echo $xml->asXML();
\t echo $status;
}
?>
看这句话'mysqli_query($连接,$查询)'。 '$ query'应该已经是一个结果对象。您也可以使用此代码注入SQL注入,查看准备好的语句。 – chris85
@ chris85这是一个Object它是我的查询来检查电子邮件 –
'$ query'虽然不是查询,但它是一个结果对象(或false),因为您已经执行了查询。 – chris85