I'm making an app with React Native and I'm struggling with a server problem. I made some HTTP requests without any body and it's all working, but now I'm trying to make a POST and it's working like a charm in Postman (request runner tool) but not when it's in the code:
So in my PHP I'm returning POST data that I sent in the body, and it's working here, but in my code it's returning null and my SQL is not executed:
save()
{
this.updateDatabase(this.state.data).then((response) => {
console.warn("id: " + response.id + " status: " + response.status);
});
}
async updateDatabase(newData)
{
const response = await fetch('http://XXX.XXX.XXX:8888/updateApplication.php', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
mode: 'no-cors',
body: JSON.stringify({
data: newData,
})
});
const json = await response.json();
return json;
}
And here is my PHP:
$json = $_POST['data'];
$data = json_decode($json)->{'data'};
$appRequest = "UPDATE app_forms SET status = '".$data->{'status'}."'WHERE id = '".$data->{'id'}."'";
$appResults = $connection->query($appRequest);
$response = array ('id'=>$data->{'id'},'status'=>$data->{'status'});
echo json_encode($response);
I don't understand why it won't work in my code... Thanks in advance for your help