1

我通过调试独立检查了服务器端,它可以正常工作,因为它应该创建一串零和一串,它应该发送回客户端。

在服务器端它看起来像这样:

    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?我该如何摆脱它?

4

1 回答 1

3

您所看到的是来自xDebug.

当您遇到 php 错误时会显示此信息。

错误来自代码示例的第 5 行

代码: $_POST["email2"]

错误: Notice: Undefined index: email2

提交表单时,您不会email2通过 POST 发送值。

您可以在调用 validate 函数之前使用isset( http://php.net/manual/en/function.isset.php ) 解决此问题

于 2013-07-09T13:12:11.733 回答