使用相同的按钮插入许多表

时间:2017-05-01 20:51:16

标签: php angularjs ionic-framework

我必须插入一些输入数据(' date',' resp')并更新其他数据(ng-repeat:' FraisFact',' CodeEnvoiColis')使用相同的按钮,问题是我使用ng-repeat,并且它多次插入数据:我正在使用php和angularJS

$scope.updateAll = function(){ 
  var promises = $scope.selected.map(function(name) {
    return $http.post("http://localhost/deb/updatFact.php", { 
        'FraisFact':name.FraisFact,
        'CodeEnvoiColis':name.CodeEnvoiColis,
        'dater':$scope.dater,
        'resp':$scope.resp
      })
  });
  $q.all(promises).then(function() {
    console.log('All names are saved');
  });   
} 

updateFact.php

<?php  

 $data = json_decode(file_get_contents("php://input"));  

   if(count($data) > 0)  
 {   

      $DateFactureRecu = mysqli_real_escape_string($connect, $data->dater);  
      $RespFacture = mysqli_real_escape_string($connect, $data->resp);  

      $query = $query = "INSERT INTO facture (DateFacture,DateFactureRecu,RespFacture) VALUES (NOW(),'$DateFactureRecu','$RespFacture') " ;

      if(mysqli_query($connect, $query))  
      {  
           echo "Facture insérée avec succès..."; 

      }  

      else  ...
  }
   if(count($data) > 0)  
 {   

      $CodeEnvoiColis = mysqli_real_escape_string($connect, $data->CodeEnvoiColis);  
      $FraisFact = mysqli_real_escape_string($connect, $data->FraisFact);  

      $query = "UPDATE colis SET FraisFact='$FraisFact',NumFacture=LAST_INSERT_ID()  WHERE CodeEnvoiColis='$CodeEnvoiColis'" ;

      if(mysqli_query($connect, $query))  ...

  }
 ?>

0 个答案:

没有答案