Dilip Belgumpi
Dilip Belgumpi

Reputation: 648

How to access the properties of an array object getting from HTTP POST request in PHP?

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

Answers (1)

Naincy
Naincy

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

Related Questions