I have a web application which uses a link and a jQuery handler to submit information through ajax to perform a function in an outside PHP file....
I am receiving this error on passing the variables
PHP Fatal error: Function name must be a string in..... on line 7 (check comment of php)
What exactly am I doing wrong?
<a href="#" id="tester" data-letterid="13" data-type="failValidate">This Link Fails</a>
$('#tester').on("click",function(){
var dataObj = {}
dataObj['letterid']=$('#tester').attr("data-letterid");
dataObj['letterid']=JSON.stringify(dataObj['letterid']);
dataObj['type']=$('#tester').attr("data-type");
dataObj['type']=JSON.stringify(dataObj['type']);
$.ajax({
url: 'super_testy.php',
type: 'POST',
data: dataObj,
dataType: 'json',
success: function(data){
alert("success!!");
return false;
},
error: function(jqXHR, textStatus, errorThrown){
alert(textStatus);}
});});
//It Fails Right Here, and says that Fatal Error, shown above
$id=$_POST('letterid');
$type=$_POST('type');
if ($type == "failValidate") { //do something, etc....}
Even after testing and adding JSON.stringify(xyz) to the variables doesn't seem to help
The $_POST
, $_GET
, $_REQUEST
superglobals are arrays, so you need to access them with bracket notation, not like a function:
$id = $_POST['letterid'];
$type = $_POST['type'];