Reputation: 648
I am trying to get the properties of an array object and save it into the DB, here is my POST method
$http({
method:"POST",
async: false,
data: {first_name:'dilip',last_name:'belgumpi'}, url:"insert.php"
});
and in insert.php
$first_name=$_POST["first_name"];
When I run this code I am getting error like this
<b>Notice</b>: Undefined index: first_name in <b>C:\xampp\htdocs\tutor_crm\insert.php</b> on line <b>10</b><br />
Upvotes: 1
Views: 109
Reputation: 2943
As you sending request through angular, need to set headers in your request.
$scope.add = function() {
var FormData = {
'first_name' : 'dilip',
'last_name' : 'belgumpi'
};
$http({
method:"post",
data: $.param({'data' : FormData}),
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
url:"insert.php"
});
File: insert.php
<?php
$data = $_POST['data'];
var_dump($data);
?>
Upvotes: 1