I am running into an issue I cannot figure out. I create a simple button that sends data with AJAX to a php file. I have the variables defined and are appearing correct in the console when clicking the button, however my PHP file is not reading the variables I am setting. The else statement in my php file is triggering.
Does anyone see why the variables are not being set in the php file?
HTML
<button class="catalogDownload downloadButton" name="Profile Catalog" id="profileCatalogPDFButton" data-catalog-now="Profile Popular Button" data-catalog-view-name="Profile Catalog">Download Now</button>
AJAX
//Download Now AJAX
var catalog_name = '';
var button_triggered = '';
$('.downloadButton').on('click', function (event) {
catalog_name = $(this).attr('name');
button_triggered = $(this).data('catalog-now');
console.log(catalog_name);
$.ajax({
url: 'urlhere.php',
type: 'POST',
data: {
'catalog_name': catalog_name,
'button_triggered': button_triggered
},
success: function (data) {
//console.log(data);
},
error: function(xhr, textStatus, errorThrown) {
alert(textStatus + "|" + errorThrown);
},
cache: false
});
});
PHP File
ini_set('display_errors', 1);
error_reporting(E_ALL);
//$catalog_name = $_POST['catalog_name'];
if(isset($_POST['catalog_name'])){
$catalog_name = $_POST['catalog_name'];
} else {
echo 'Catalog Name is not reading';
}
Notice: Undefined variable: catalog_name in /home.php on line 36
Notice: Undefined variable: button_triggered in /home/.php on line 36
Connection failed: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'catalog_name' cannot be null` – Paul Nov 06 '18 at 21:48