PHP echo $ result' {" status" :"成功"}&#39 ;;

时间:2015-06-18 23:50:04

标签: php

你能告诉我这个功能有什么问题。 在视频中找到了它:https://www.youtube.com/watch?v=871_PMieyxI(1:24)

我收到错误:解析错误:语法错误,意外'' {"状态" :"成功"}'' (T_CONSTANT_ENCAPSED_STRING),期待','或';'在第26行的C:\ xampp \ htdocs \ myproject \ application \ controllers \ usercontroller.php

第26行是这一行:echo $ result' {" status" :"成功"}';

public function add()
{
    $postdata = file_get_contents("php://input");
    $request = json_decode($postdata);
    $name = $request->name;
    $city = $request->city;
    $id = $this->user_model->AddUser($name,$city);
    if($id)
    {
        echo $result '{"status" : "success"}';
    } else {
        echo $result '{"status" : "failure"}';
    }
}

1 个答案:

答案 0 :(得分:3)

如果$result中没有任何其他内容,则可以

if($id)
    {
        echo '{"status" : "success"}';
    } else {
        echo '{"status" : "failure"}';
    }

但如果你在$ result中有更多数据,那么你错过了. 所以你得到一个解析错误,因为你的代码没有正确连接。