I'm learning Angular 8 and now trying to send a post request from localhost to the api on shared hosting (tried on localhost before the server). I had the issue of origin source and fixed by installing Moesif Orign & CORS Changer extension for chrome. I have this code now
onCreatePost(userData: { username: string; email: string, password: string, school: string }) {
console.log(userData);
this.http.post('http://example.net/insert.php', userData).subscribe( (response) => {
console.log(response);
});
}
Here's the userData log
{username: "test name", email: "user@mail.com", password: "123456", school: "test school"}
I try to save the post data first before handling it
$postData = $_POST;
$q = $db->prepare("insert into post (data) value ('$postData')");
$q->execute();
$result['message'] = "test message";
echo json_encode($result);
but I get Array
as a result in the field. I changed it too json_encode($_POST)
but I get []
in the field. I can't find the data sent in the post request why is that?