0

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"}';
    }
}
Davo
  • 129
  • 2
  • 13
  • 1
    `echo $result . '{"status" : "success"}';` should make the error go away. it's not concatenated properly hence the parse error. take note of the added `.`. – tradyblix Jun 18 '15 at 23:53

1 Answers1

3

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.

Kio Coan
  • 561
  • 2
  • 7
  • 24