title: How to Update/Edit data in database with AngularJS
body: <p>Working on a web app , I just added the below update code and it's not working .
  The summary of all the below code is : </p>
  
  <ul>
  <li>Click a Button called <code>update</code></li>
  <li>It brings out the FORM which should contain the values of the clicked/current product.</li>
  <li>Now when I hit save in this form it should update the database but it is not.</li>
  <li>I am using <code>$_GET</code> in PHP file (update.php) to get the current Product <code>ID</code>.And then getting all data of that product via that <code>ID</code>.</li>
  </ul>
  
  <p>PS: There is no error in console.</p>
  
  <p><strong>UPDATE CODE:</strong></p>
  
  <pre><code>&lt;?php 
      include "includes/connection.php";
      switch($_GET['action']) {
          case 'update_entry' :
              $data = json_decode(file_get_contents("php://input"));
              $index = $data-&gt;id; 
              $productname = $data-&gt;pname;
              $company = $data-&gt;company;
              $price = $data-&gt;price;
              $quantity = $data-&gt;quantity;
              if(isset($productname) &amp;&amp; !empty($productname) &amp;&amp; isset($company) &amp;&amp; !empty($company) &amp;&amp; isset($price) &amp;&amp; !empty($price) &amp;&amp; isset($quantity) &amp;&amp; !empty($quantity)){
                  $query = "UPDATE `product` SET `id`='$index',`name`='$productname',`company`='$company',`price`='$price',`quantity`='$quantity' WHERE id= $index";
  
                  if(mysqli_query($con, $query)) {
                    return true;
                  } else {
                    echo "Error: " . $sql . "&lt;br /&gt;" . mysqli_error($con);
                  }
                  break;
              }   
      }
  ?&gt;
  </code></pre>
  
  <p><strong>Controller</strong> :</p>
  
  <pre><code>myApp.controller("updateCtrl",['$scope','$http','$routeParams','$location',function($scope,$http,$routeParams,$location){
      $scope.update = function(){
           var currentId = $routeParams.id;
           $http.post("update.php?action=update_entry",{'id':currentId})
               .then(function(data){
                  $location.path('/viewproduct');
           });
      }
  }]);
  </code></pre>
  
  <p><strong>HTML:</strong></p>
  
  <pre><code>&lt;form style="padding:10px" ng-controller="updateCtrl"&gt;
      &lt;div class="form-group"&gt;
          &lt;label for="ProductName"&gt;Product Name&lt;/label&gt;
          &lt;input type="text" class="form-control" placeholder="{{product.name}}" ng-model="productname" required&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label for="company"&gt;Company &lt;/label&gt;
          &lt;input type="text" class="form-control" placeholder="{{product.company}}" ng-model="company" required&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label for="company"&gt;Price &lt;/label&gt;
          &lt;input type="text" class="form-control" placeholder="{{product.price}}" ng-model="price" required&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label for="company"&gt;Quantity &lt;/label&gt;
          &lt;input type="text" class="form-control" placeholder="{{product.quantity}}" ng-model="quantity" required&gt;
      &lt;/div&gt;
      &lt;button type="submit" class="btn btn-default" ng-click="update()"&gt;Save updated data&lt;/button&gt;
      &lt;a href="#/viewproduct" class="btn btn-danger"&gt;Cancel&lt;/a&gt;
      &lt;h1 ng-if="successMessage == 0"&gt;Great Data is Updated!&lt;/h1&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Update Button:</p>
  
  <pre><code>&lt;td ng-controller="updateCtrl"&gt;&lt;a class="btn btn-primary" href="#/updateproduct/action={{product.id}}" &gt;Update&lt;/a&gt;&lt;/td&gt;     
  </code></pre>