我用调试独立地检查了服务器端,它可以正常工作,因为它应该创建一个零和一的字符串,并将其发送回客户端。
在服务器端,它看起来像这样:
if (validateInput($_POST["user"],
$_POST["password1"],
$_POST["password2"],
$_POST["email1"],
$_POST["email2"]))
{
$_subscriber = new subscriber($_POST["user"],$_POST["password1"],$_POST["email1"],CURRENT_TIME);
subscriberInsertion($_subscriber);
}
/** function subscriberInsertion($_subscriber) insert a subscriber to DB*/
function subscriberInsertion($_subscriber)
{
$query = "INSERT INTO users (user,value,email,date) VALUES('{$_subscriber->getUser()}',
'{$_subscriber->getPassword()}',
'{$_subscriber->getEmail()}',
'{$_subscriber->getDate()}')";
$dbObj = new DB_MySQL(DB_users_HOST,DB_users_USER,DB_users_PASS,DB_users_NAME);
if ($dbObj ->execute($query))
{
header('Location:' . URL_HTML_PATH . "index.html");
exit;
}
}
/**validateInput main function for validation of good credntails and emails */
function validateInput($user,$pass1,$pass2,$email1,$email2)
{
$regexUser = "/^(?=.{1,20}$)[a-zA-Z0-9]+$/"; //all letters ad number and size between 1-20
$regexPwd = "/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,10}$/"; //Password must contain 6-10 characters and
// at least one number, one letter and one
//Regex mail
$regexMail = "/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/";
$response = "";
//check user name//
$response = $response . checkRegex($regexUser,$user); //at location 0 in string
//check password//
$response = $response . checkRegex($regexPwd,$pass1); //at location 1 in string
$response = $response . textCompare($pass1,$pass2); //at location 2 in string
//check mail//
$response = $response . checkRegex($regexMail,$email1); //at location 3 in string
$response = $response . textCompare($email1,$email2); //at location 4 in string
//check user name existence
$response = $response . checkExistaneceOfUser($user); //at location 5 in string
echo $response;
}
您可以看到echo $response
最终返回的是一个零和一的字符串。
在客户端,这是Java脚本,正在发送带参数的请求并等待响应:
/**function checkUserExistance(str) to check if user exist*/
function sendToValidation(data)
{
var xmlhttp;
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var response = xmlhttp.responseText;
alert(response);
}
}
xmlhttp.open("POST",url + page,true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(data);
}
我从服务器端得到的响应很好,问题是我收到的是一个很大的奇怪的xml:
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'> <tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: email2 in D:\wamp\www\MyHome2\php\databasebuilder.php on line <i>25</i></th></tr> <tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr> <tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr> <tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0010</td><td bgcolor='#eeeeec' align='right'>163616</td><td bgcolor='#eeeeec'>{main}( )</td><td title='D:\wamp\www\MyHome2\php\databasebuilder.php' bgcolor='#eeeeec'>..\databasebuilder.php<b>:</b>0</td></tr> </table></font> 001011"
我在这里只放置了xml的一小部分,因为它太大了,正如您在xml的末尾看到的,我得到001011,这是我期望的响应。为什么我的结果中包含此xml?我如何摆脱它?
您所看到的是的输出xDebug
。
出现php错误时显示。
错误来自代码示例的第5行
代码: $_POST["email2"]
错误: Notice: Undefined index: email2
提交表单后,您没有email2
通过POST发送值。
您可以在调用validate函数之前使用isset
(http://php.net/manual/en/function.isset.php)修复此问题
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句