2016-07-26 3 views
0

私はangleとphpでプロジェクトを構築しています。私は "顧客"テーブルから顧客のリストを表示するHTMLページを持っています。私は "削除"ボタンを押して行を削除しようとすると、削除されず、エラーを表示しません。誰でも助けてくれますか?角度とPHPでデータベース行を削除するには?

これは私のコードです:

コントローラー:

$scope.delete = function(deletingId, $index) { 
     var params = $.param({"customer_id":deletingId}); 
     $http({ 
      headers: {'Content-Type': 'application/x-www-form-urlencoded'}, 
      url: 'http://localhost:8081/hamatkin/api/delete-customer.php/', 
      method: "GET", 
      data: params 
     }).success(function(data){ 



      // var arr=JSON.parse(JSON.stringify(data)); 
      // console.log(data); 
      var arr=JSON.parse(JSON.stringify(data)); 
      $scope.customerDetails = arr; 
      var arr2 = arr.split(","); 
       arr2.splice($index, 1); 


     }); 
     } 

Php-削除-customer.phpを

<?php header('Content-Type: text/html; charset=utf-8'); 
$connect=mysqli_connect("localhost", "root", "", "hamatkin"); 

    include_once 'Customer.php'; 
mysqli_query($connect,"SET character_set_client = utf8"); 
mysqli_query($connect,"SET character_set_connection = utf8"); 
mysqli_query($connect,"SET character_set_results = utf8"); 
// Check connection 
if (mysqli_connect_errno()) { 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
} 
$customer = new Customer(); 


if(isset($_GET['customer_id'])){ 
    $customer_id = $_GET['customer_id']; 
    $del = "DELETE FROM posts WHERE customer_id='".$customer_id."'"; 
    mysql_query($connect, $del); 
} 


$newURL = "/hamatkin/#/customerCards"; 
header('Location: '.$newURL); 
?> 

HTML

<tr ng-repeat="x in customers | filter:search_query | orderBy: order_query:reverse_query"> 

      <td>{{ x.customer_id}}</td> 
      <td>{{ x.kind_Of_Customer}}</td> 
      <td>{{ x.full_name}}</td> 
      <td><a ng-click="delete(x.customer_id, $index)" class="btn btn-primary btn- active">מחיקה</td> 
+0

なぜあなたはng-click = "delete(x.customer_id、$ index? –

+0

@vishal何をすることをお勧めしますか? – tanyaa

+0

$ index –

答えて

0

私はあなたがしていることに気づきましたを使用して210、DBを接続するために、あなたはmysqlを使用しているため、クエリを実行し、あなたが同じLIBを使用する必要があり、mysqli_query()

+0

ありがとう、私はmysqli_query($ connect、$ del)に変更しました。でも同じです – tanyaa

+0

ブラウザは '../ delete-customer.php?customer_id = 1'のようなリクエストを送りますか? –

+0

私はそれが何を意味するのか正確にはわかりません...もっと具体的に何をすべきですか? – tanyaa

0

を通して、あなたのクエリを実行しようとした角度

<html ng-app="mainApp"> 
     <head> 
     <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script> 
     <script> 
     angular.module('mainApp').controller('myCtrl',function($scope,$http){ 
      //getting the table data from this http from database 
       $http({ 
        method : "GET", 
        url : "http://localhost/em/mod.php/info", 
        headers: {'Content-Type': 'application/x-www-form-urlencoded'} 
        }).then(function mySucces(response) { 
        $scope.mydata=response.data; 
        }, function myError(response) { 
        $scope.mydata=response.statusText; 
       }); 
        $scope.delete=function(idd) 
     {   

      //here delete passes the id to the php by which we will delete the row 
      $http({ 
       method : "DELETE", 
       url : "http://localhost/em/mod.php/info", 
       data:{ 
       "id":idd, 
       }, 
       headers: {'Content-Type': 'application/x-www-form-urlencoded'} 
       }).then(function mySucces(response) { 
        $http({     //here we are refreshing the table data 
        method : "GET", 
        url : "http://localhost/em/mod.php/info" 
        }).then(function mySucces(response) { 
        $scope.mydata=response.data; 
        }, function myError(response) { 
        $scope.mydata=response.statusText; 
        }); 
       }, function myError(response) { 
       $scope.mydata=response.statusText; 
      }); 
     } 

     </script> 
     //suppose we got the table data in $scope.mydata 
     </head> 
     <body ng-controller="myCtrl"> 

     //Now below table we are showing our data and its id is passing in <a> delete when click press it send its id to the delete function 

      <table border="1"> 
       <tr> 
        <th>Predefine Message</th> 
        <th>CreatedBy</th> 
        <th>Status</th> 
        <th>Action</th> 
       </tr> 
       <tr ng-repeat="rs in mydata"> 
        <td> 
        {{rs.message}} 
        </td> 
        <td> 
        {{rs.createdby}} 
        </td> 
        <td> 
        Active 
        </td> 
        <td> 
        <a href="" ng-click="delete(rs.id)">Delete</a> 
        </td> 
       </tr> 
      </table> 



     </body> 
    </html> 
とコンセプトを削除する簡単な行を理解しよう
関連する問題