Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Include the module as a dependency of our main AngularJS app module
- var app = angular.module('notesApp', [
- 'ngRoute'
- ]);
- // App routing
- app.config(['$routeProvider', function($routeProvider) {
- $routeProvider
- .when('/', {
- templateUrl: "home.html"
- })
- .when('/main/:itemn', {
- templateUrl: "index1.html"
- })
- .when('/cart', {
- templateUrl: "cart.html"
- })
- .when('/test', {
- templateUrl: "addremove.php"
- })
- .when('/addremove', {
- templateUrl: "addremove.php"
- })
- }]);
- //main controller
- app.controller("mainController", ['$scope', '$http', '$routeParams', '$location', '$window', function($scope, $http, $routeParams, $location, $window) {
- $scope.products = [];
- var arr = $location.$$path.split('/');
- $scope.itemn = arr[2];
- // move to new url
- $scope.go = function(path) {
- $location.path(path);
- };
- $http.get('modeldata.php').then(function(response) {
- $scope.items = response.data.records;
- }, function(errResponse) {
- console.error('Error while fetching notes');
- });
- $http.get('cart.php').then(function(response) {
- $scope.carts = response.data.records;
- // $scope.products=$scope.items;
- }, function(errResponse) {
- console.error('Error while fetching notes');
- });
- // Add new record
- $scope.addItem = function(item){
- var variableName = {'a':'1'};
- $http({
- method: 'post',
- url: 'addremove.php',
- data: variableName,
- headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
- })
- $scope.go('/test');
- }
- }]);
- data are flow in addremove file to insert into mysql server table
- <?php
- $servername = "XXXXX";
- $username = "XXXXX";
- $password = "XXXXX";
- $dbname = "XXXXXXX";
- // Create connection
- $conn = mysqli_connect($servername, $username, $password, $dbname);
- // Check connection
- if (!$conn) {
- die("Connection failed: " . mysqli_connect_error());
- }
- $data = json_decode(file_get_contents("php://input"));
- echo $data;
- $itemno = $data->a;
- $query="INSERT INTO cart(itemno) values ( '$itemno')";
- if (mysqli_query($conn, $query)) {
- echo 'Data Deleted Successfully...';
- } else {
- echo 'Failed';
- }
- $lastinsert_id = mysqli_insert_id($conn);
- ?>
Add Comment
Please, Sign In to add comment