在我的其他服务器上,我有一个向服务器的数据库添加新行的函数,并返回一个响应:
这是我的功能:
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
}
答案 0 :(得分:1)
你正在回应:
echo $login.$password.$address;
在设置标题之前。
顺便说一下,你不应该使用get来添加东西 - 改为使用POST
。