0

I would need some help on my rest app plz. I'm trying to understand the reason of this error message "Trying to get property of non-object" but I'm stuck

I commented the following snippet who's manage a formations create form :

header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");

include_once '../config/database.php';      // Database connection file 
include_once '../objects/formation.php';    // Formation class file

$database = new Database();
$db = $database->getConnection();

$formation = new Formation($db);            // class Formation              

$data = json_decode(file_get_contents("php://input"));  // Posted datas 

$formation->formation = $data->formation;   // This line return an error : Trying to get property of non-object

// var_dump($data)      return an object(stdClass) with a ["formation"] property
// var_dump($formation) return an object(Formation) with a ["formation"] property

if($formation->createFormation()){
  echo '"Message": "Success"';
  }
  else {
    echo '"Message": "Failed"';
  }

I don't understand why the line "$formation->formation = $data->formation;" doesn't work ...

Did I use a wrong syntax ? Any advices ? Thx

amt59
  • 67
  • 4

0 Answers0