I am trying to perform an AJAX request through jquery-confirm plugin loading the file data from a form through its ajax-load function and then updating the information to a PHP file and ultimately to a database.
However, this is resulting in the following error.
Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in Unknown on line 0
Warning: Cannot modify header information - headers already sent in Unknown on line 0
I have attempted to even throw in a blank variable as the meaning of this error is it not POSTing the data across to the page. This simply throws back an undefined index, confirming that it isn't posting the data.
Some posts on this site have said to change the php.ini files etc, as I am using a university server, we do not have access to change these files.
Here is my JS file which is performing the AJAX function
function addSubject(){
$("#addBtn").on('click', function() {
$.confirm({
title: 'Manage Subjects',
content: 'url: addSubjectForm.html',
buttons: {
addSubject: {
text: 'Add New Subject',
btnClass: 'btn-info',
action: function () {
var findSubject = this.$content.find('input#newSubject');
var findDescript = this.$content.find('input#newDescript');
var newSubject = findSubject.val();
var newDescript = findDescript.val();
if (newSubject === '' || newDescript === '') {
$.alert({
content: 'One of the fields from the form was empty',
type: 'red'
});
return false;
} else {
$.ajax({
url: "../ajax/admin/addSubject.php",
type: "POST",
data: {title: newSubject, description: newDescript, blank: 'blank'},
cache: false,
contentType: false,
processData: false,
success: function (result) {
$.alert({
content: result,
type: 'green'
});
}
});
console.log(newSubject + " " + newDescript);
}
}
},
close: {
text: 'Close',
btnClass: 'btn-danger'
}
}
});
});
}
The PHP page where I access the variables is here:
<?php
$title = filter_input(INPUT_POST, "title");
$description = filter_input(INPUT_POST, "description");
$test = $_POST['blank'];
echo $test;
echo "$title $description";
The blank variable in these files are simply for testing purposes only.
Thanks in advance.
Try :
$title = filter_input(INPUT_POST, 'title', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); $description = filter_input(INPUT_POST, 'description', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);