Advertisement
Guest User

Untitled

a guest
Aug 27th, 2015
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html ng-app="myApp">
  3. <head>
  4. <title>CRUD AngularJS</title>
  5. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js</script>
  6. </head>
  7. <body ng-controller="MainCtrl as ctrl">
  8. <form ng-submit="ctrl.submit()">
  9. Nome<br>
  10. <input type="text" ng-model="ctrl.user.nome"><br>
  11. Email<br>
  12. <input type="text" ng-model="ctrl.user.email"><br>
  13. Senha<br>
  14. <input type="password" ng-model="ctrl.user.senha"><br>
  15. <input type="submit" id="submit" value="Submit" />
  16. </form>
  17.  
  18. <script type="text/javascript">
  19. angular.module('myApp', [])
  20. .controller('MainCtrl', ['$scope', '$http', function($scope, $http){
  21. $scope.list = [];
  22. var self = this;
  23. self.submit = function() {
  24. console.log('User clicked submit with ', self.user);
  25. $http.post('php/salvar.php', {'nome': $scope.nome, 'email': $scope.email, 'senha': $scope.senha})
  26. .then(function(response) {
  27. console.log(response.status);
  28. console.log(response.data.msg);
  29.  
  30. }, function(response) {
  31. console.log(response.status);
  32. console.log(response.msg);
  33.  
  34. });
  35. }
  36. }]);
  37. </script>
  38. </body>
  39. </html>
  40.  
  41. ?php
  42. $user = 'root';
  43. $password = 'root';
  44. $db = 'angularDB';
  45. $host = 'localhost';
  46.  
  47. $con = mysqli_connect("localhost", $user, $password, $db);
  48.  
  49. // Check connection
  50. if (mysqli_connect_errno())
  51. {
  52. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  53. }
  54.  
  55. $nome = $_POST['nome'];
  56. $email = $_POST['email'];
  57. $senha = $_POST['senha'];
  58.  
  59. $ins = mysqli_query($con, "INSERT INTO users VALUES (NULL, '$nome', '$email', '$senha')");
  60.  
  61. echo json_encode( array('status' => 1, 'msg' => 'Cadastro efetuado com sucesso!'));
  62. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement