저는 각도와 PHP를 사용하여 프로젝트를 구축하고 있습니다. 모든 데이터를 검색 할 수있는 "고객"테이블이 있지만 한 행을 삭제하는 데 문제가 있습니다. "고객"에게 "주문"이있는 경우 "행"고객 "을 삭제할 수 없습니다. "고객"에게 "주문"이 없다면 아무런 문제없이 삭제할 수 있습니다. phpmyadmin = # 1451 - 상위 행을 삭제하거나 업데이트 할 수 없습니다 : 외래 키 제약 조건이 실패합니다. 누구든지 도와 드릴 수 있습니까? 삭제외래 키가 있기 때문에 데이터베이스 행을 삭제할 수 없습니다
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();
}
$data = json_decode(file_get_contents("php://input"));
$x=$data->customer_id;
$customer_id = $data->customer_id;
$del = "DELETE FROM customers WHERE customer_id=".$customer_id;
mysqli_query($connect, $del);
}
$newURL = "/hamatkin/#/customerCards";
header('Location: '.$newURL);
?>
컨트롤러 :
이$scope.delete = function(deletingId, $index) {
var params = $.param({"customer_id":deletingId});
$http.post('api/customers-tab/delete-customer.php',{"customer_id":deletingId})
.success(function(data){
var arr=JSON.parse(JSON.stringify(data));
$scope.customerDetails = arr;
var arr2 = arr.split(",");
arr2.splice($index, 1);
$route.reload();
});
}
HTML 코드 : 당신은 당신의 테이블에 CascadeDelete를 추가 할 수
<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> {{ x.id}} </td>
<td> {{ x.city}} </td>
<td><a href="/hamatkin/index.html#/customerCardDetails/{{ x.customer_id}}" class="btn btn-primary btn- active">הצג פרטי לקוח </a></td>
<td><a ng-click="delete(x.customer_id, $index)" class="btn btn-primary btn- active">מחיקה</td>
무엇을 도와 드릴까요? 데이터베이스의 제약 조건을 위반하는 작업을하려고합니다. 제약 조건을 제거하거나 준수하십시오. 그리고 당신이 [SQL injection attacks] (http://bobby-tables.com) –
@MarcB에 내가 할 수있는 다른 어떤 것도 취약하다는 것에주의하십시오. – tanyaa
"내가 할 수있는 일은 아무것도 없다."는 Marcs의 의견에서 취한 것이 아닙니다. 선택 사항은 아무 것도하지 않거나 테이블에서 외래 키 구속을 제거하는 것입니다. – castis