Store Angularjs form data in database using php -


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 code store form data in database.. not working...i complete new angularjs...i donno went wrong... pls me..

you have several errors:

js (you need $scope link 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> 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -