I'm Working on AngularJs about a week and I'm trying to insert a value into mysql database through a PHP.
my form look like this
<form ng-model="far_form" name="far_reg" ng-submit="register(far_reg.$valid)" novalidate="true"
ng-controller= "farform_contr">
<input type="text" id="First Name" placeholder="Name" ng-model="far.first_name" >
<input type="text" id="Email" placeholder="Email" ng-model="far.email">
<input type="text" id="Mobile" placeholder="Mobile" ng-model="far.mobile">
</form>
And Controler is
.controller('farform_contr',['$scope', '$http', function($scope, $http) {
$scope.register = function(isValid) {
if (isValid) {
$http({
method : 'POST',
url : 'submit.php',
dataType: 'json',
data : $scope.far, //forms user object
headers : {'Content-Type': 'application/x-www-form-urlencoded'}
}).
success(function(data, status) {
console.log(far);
$scope.status = status;
$scope.data = data;
})
}else{
alert('Form is not valid');
}
}
}]);
I have couple of other controller in the same file Which are working fine.
submit.php is
<?php
$post_date = file_get_contents("php://input");
$data = json_decode($post_date);
$name=$data['first_name'];
$email=$data['email'];
$mobile=$data['mobile'];
echo "<script>alert('$name')</script>";
echo "<script>alert('$email')</script>";
echo "<script>alert('$mobile')</script>";
?>
All the echo's are returning null I don't know where i'm going wrong.
$httpservice, the way of retrieving response isargument.datain success function. Have you got any response in success?