-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 を使うべきではありません -POST代わりに a を使ってください。

于 2013-08-12T15:27:55.760 に答える