-3

在我的休息服务器上,我有一个向服务器数据库添加新行并返回响应的函数:

这是我的功能

    private function addUser(){
        echo "addUser\n ";

        $login=$_REQUEST['login'];
        $password=$_REQUEST['password'];
        $firstname=$_REQUEST['firstname'];
        $lastname=$_REQUEST['lastname'];
        $sex=$_REQUEST['sex'];
        $situation=$_REQUEST['situation'];
        $email=$_REQUEST['email'];
        $telephone=$_REQUEST['telephone'];
        $address=$_REQUEST['address'];

        echo $login.$password.$address;

        $sql = "insert into users(login,password,firstname,lastname,sex,situation,email,telephone,address)
        values('$login','$password','$firstname','$lastname','$sex','$situation','$email','$telephone','$address')" ;

        if (!mysql_query($sql))
          {
            die('Error: ' . mysql_error());
          }
          else
          {
            echo 'SUCCESS: ';
          }
        $success = array('status' => "Success", "msg" => "Successfully one record created.");
        $this->response($this->json($success),200);
    }

但是在响应中我不断收到这些警告

addUser samuel0757bed3d74ccc8fc8e67a13983fc95dca20940777avbombardierSUCCESS:
Warning: Cannot modify header information - headers already sent by (output started at /mnt/153/sda/7/8/darate/rest/api.php:140) in /mnt/153/sda/7/8/darate/rest/Rest.inc.php on line 115

Warning: Cannot modify header information - headers already sent by (output started at /mnt/153/sda/7/8/darate/rest/api.php:140) in /mnt/153/sda/7/8/darate/rest/Rest.inc.php on line 116
{"status":"Success","msg":"Successfully one record created."}

以下是似乎是错误来源的行

private function set_headers(){
            header("HTTP/1.1 ".$this->_code." ".$this->get_status_message());//line 115
        header("Content-Type:".$this->_content_type);//116
    }
4

1 回答 1

1

你在呼应的东西:

echo $login.$password.$address;

在设置标题之前。

顺便说一句,你不应该使用 get 添加东西 - 使用 aPOST代替。

于 2013-08-12T15:27:55.760 回答