2016-07-26 3 views
0

Я строю проект с угловым и 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

Могу ли я узнать, почему вы передаете $ index в ng-click = "delete (x.customer_id, $ index? –

+0

@vishal, что вы предлагаете делать? – tanyaa

+0

want to понять почему $ index –

ответ

0

Я заметил, что вы используя mysqli для подключения БД, то вы используете 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> 
Смежные вопросы