duanjue6584 2015-06-18 23:50 采纳率: 100%
浏览 228
已采纳

PHP echo $ result'{“status”:“success”}'; [重复]

This question already has an answer here:

Could you please tell me what is wrong with this function. Found it in the video: https://www.youtube.com/watch?v=871_PMieyxI (1:24)

I'm getting the error: Parse error: syntax error, unexpected ''{"status" : "success"}'' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';' in C:\xampp\htdocs\myproject\application\controllers\usercontroller.php on line 26

Line 26 is this line: echo $result '{"status" : "success"}';

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"}';
    }
}
</div>
  • 写回答

1条回答 默认 最新

  • dslfjrmz70457 2015-06-18 23:57
    关注

    If you don't have anything else in $result you could just

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

    But if you have more data in $result, you missed the . So you get a parse error because your code is not being concatenated correctly.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器