-3

On my rest Server i have a function that adds a new row to the server's database, and returns a response:

Here is my function:

    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);
    }

But the on the response i keep getting these warnings :

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."}

The following are the lines that seem to be the source of the Error

private function set_headers(){
            header("HTTP/1.1 ".$this->_code." ".$this->get_status_message());//line 115
        header("Content-Type:".$this->_content_type);//116
    }
Hossam Oukli
  • 1,296
  • 3
  • 19
  • 42

1 Answers1

1

You are echoing stuff:

echo $login.$password.$address;

before setting headers.

By the way, you should not use a get to add stuff - use a POST instead.

moonwave99
  • 21,957
  • 3
  • 43
  • 64