Guest User

Untitled

a guest
Oct 25th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. //Include the module as a dependency of our main AngularJS app module
  2. var app = angular.module('notesApp', [
  3. 'ngRoute'
  4. ]);
  5.  
  6. // App routing
  7. app.config(['$routeProvider', function($routeProvider) {
  8. $routeProvider
  9. .when('/', {
  10. templateUrl: "home.html"
  11. })
  12.  
  13. .when('/main/:itemn', {
  14. templateUrl: "index1.html"
  15. })
  16. .when('/cart', {
  17. templateUrl: "cart.html"
  18. })
  19. .when('/test', {
  20. templateUrl: "addremove.php"
  21. })
  22. .when('/addremove', {
  23. templateUrl: "addremove.php"
  24. })
  25.  
  26.  
  27. }]);
  28. //main controller
  29. app.controller("mainController", ['$scope', '$http', '$routeParams', '$location', '$window', function($scope, $http, $routeParams, $location, $window) {
  30. $scope.products = [];
  31. var arr = $location.$$path.split('/');
  32. $scope.itemn = arr[2];
  33. // move to new url
  34. $scope.go = function(path) {
  35. $location.path(path);
  36. };
  37. $http.get('modeldata.php').then(function(response) {
  38. $scope.items = response.data.records;
  39.  
  40. }, function(errResponse) {
  41. console.error('Error while fetching notes');
  42. });
  43. $http.get('cart.php').then(function(response) {
  44. $scope.carts = response.data.records;
  45. // $scope.products=$scope.items;
  46. }, function(errResponse) {
  47. console.error('Error while fetching notes');
  48. });
  49. // Add new record
  50. $scope.addItem = function(item){
  51. var variableName = {'a':'1'};
  52. $http({
  53. method: 'post',
  54. url: 'addremove.php',
  55. data: variableName,
  56. headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
  57. })
  58. $scope.go('/test');
  59.  
  60. }
  61.  
  62. }]);
  63.  
  64.  
  65. data are flow in addremove file to insert into mysql server table
  66.  
  67. <?php
  68. $servername = "XXXXX";
  69. $username = "XXXXX";
  70. $password = "XXXXX";
  71. $dbname = "XXXXXXX";
  72. // Create connection
  73. $conn = mysqli_connect($servername, $username, $password, $dbname);
  74. // Check connection
  75. if (!$conn) {
  76. die("Connection failed: " . mysqli_connect_error());
  77. }
  78. $data = json_decode(file_get_contents("php://input"));
  79. echo $data;
  80. $itemno = $data->a;
  81. $query="INSERT INTO cart(itemno) values ( '$itemno')";
  82. if (mysqli_query($conn, $query)) {
  83. echo 'Data Deleted Successfully...';
  84. } else {
  85. echo 'Failed';
  86. }
  87.  
  88. $lastinsert_id = mysqli_insert_id($conn);
  89.  
  90. ?>
Add Comment
Please, Sign In to add comment