I've tried everything, I even tried sending other data from my code in JavaScript and nothing works, PHP keeps telling me that $_POST is empty, whenever I try file_get_contents("php://input")
it also gives me an empty array, or a null or whatever. I'm trying to send this through JSON, I think that isn't exactly necessary but either way, PHP receives nothing, regardless of what I send. I checked through chrome to see if something was getting sent, and it was the POST request gets logged in Network, and the request payload displays the data I'm trying to send but whenever I open my PHP page in my browser it displays null, Array(), or empty. I thought it might have something to do with UTF-8 but I don't think so. I've been trying this for hours. There has got to be something wrong in here that I'm not seeing.
Here is my javascript code:
window.onload = function findSubmitButton() {
var button = document.querySelector(".send_info").addEventListener("click", serverInteraction);
}
function serverInteraction() {
var xmlhttp;
var inputArray;
var finalArray = [];
var JSONArray;
var userId;
if (window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} else {
throw new Error("Your Browser is not compatible with XMLHTTP");
return false;
}
inputArray = document.querySelectorAll("input[type=text]")
for(var i = 0; i < inputArray.length; i++){
finalArray[i] = inputArray[i].value;
}
console.log(finalArray);
JSONArray = JSON.stringify({finalArray: finalArray});
console.log(JSONArray);
xmlhttp.open("POST","phpFiles/sendUserInfo.php", true);
xmlhttp.setRequestHeader("Content-type","application/json;charset=UTF-8");
xmlhttp.send(JSONArray);
}
This is my PHP for now:
<?php
$connection = oci_connect('User', 'password', 'localhost/dbXDB');
var_dump($_POST);
if(!$connection){
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
else {
echo "Connection Established";
}
?>
Ignore the database connection stuff, it's pretty much irrelevant until I can get my data through. I would really appreciate if someone could help me out with this, it cannot be as hard or difficult as it has been, since a lot of other people have done this before. I really can't figure out why it doesn't seem to work.
EDIT: This is what my response log says:
{"finalArray":["1","2","3","4","5","6"]}Connection Established
I see my JSON right there, I don't know if that means that it worked. The console log still gave me nothing.