Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

My index.html:

<form name="myForm" ng-controller="Ctrl" ng-submit="save(user)">
  <label>Name:</label>
  <input type="text" ng-model="user.name"/><br /><br />
  <label>Email:</label>
  <input type="text" ng-model="user.email"/><br /><br />
  <input type="submit" value="Submit"/>
</form>

script.js

   function Ctrl($scope,$http)
   {

$scope.save = function(user)
{
   var data={
   name: user.name,
   email:user.email
        }
        console.log(data);
 $http.post("insert.php",data).success(function(data){
   console.log(data);
 });


}
 }      

insert.php

<? php

  $data = json_decode(file_get_contents('php://input'), true);
  if (json_last_error() === JSON_ERROR_NONE) {
  // use $data instead of $_POST
   print_r($data);

  ?>

This is my code to store form data in database.. but its not working...i am complete new to angularjs...i donno where i went wrong... pls help me..

share|improve this question
 
insert.php - is this a valid url? Haven't used php in ages but I can't remember putting .php on the end of everything! Depends on your server config of course... You might put a .error() callback and see if that returns anything. –  Ian Haggerty Aug 13 at 11:48
 
@IanHaggerty:its not giving anything –  kisna Aug 13 at 11:58
add comment

1 Answer

You have several errors:

JS (You need to $scope to link your variables)

$scope.save = function() {
   var data = {
      name: $scope.user.name,
      email: $scope.user.email
   }

   $http.post("insert.php", data).success(function(data, status, headers, config){

   });
}

HTML

<form name="myForm" ng-controller="Ctrl" ng-submit="save()">
  <label>Name:</label>
  <input type="text" ng-model="user.name"/><br /><br />
  <label>Email:</label>
  <input type="text" ng-model="user.email"/><br /><br />
  <input type="submit" value="Submit"/>
</form>
share|improve this answer
 
still the same thing happening...its not going to insert.php...in success function if i say console.log(data) it displaying the complete php code...i donno y... –  kisna Aug 14 at 3:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.