Unable to post using AngularJS & PHP
Why do you use php://input? Is there a reason why you are not using $_POST to access the posted data? If a POST-Request hits php the global associative array $_POST gets created. Each index will match one of your name-attributes from your form and contain its value.
The errors displayed could come from this approach because php://input can be anything, so $data can be. If that's the case you try to assign values ($reservation->name = $data->name;) out of an object which is actually not an object.
// get posted data$data = json_decode(file_get_contents("php://input"));// set product property values$reservation->name = $data->name;$reservation->eMail = $data->eMail;$reservation->phoneNumber = $data->phoneNumber;$reservation->colorScooter = $data->colorScooter;$reservation->amountScooters = $data->amountScooters;$reservation->inputDate = $data->inputDate;$reservation->returnDate = $data->returnDate;$reservation->category_id = $data->category_id;$reservation->created = date('Y-m-d H:i:s');
clarify the datatype of $data and make sure it stays the same no matter what. (try using var_dump instead of echo or print_r, grants additional information)
make sure to check all variable values and array values before doing any transaction. You can validate them at any point you want by using
isset()
and
is_array()
So, you will get clear idea about whic one is not set at the right place. So you will be able to trace it very clearly. Otherwise you will waste your time by tracing the problem.