我正在使用angular和php构建项目,我有一个客户表,我可以检索所有数据。我添加了删除按钮来删除行,但它只在html页面上删除而不是从数据库中删除(当我刷新所有数据返回时)。有人可以帮忙吗?我不知道如何处理代码
PHP:
<?php error_reporting(E_ALL); ini_set('display_errors', 1);
$connect=mysqli_connect('localhost', 'root', '', 'hamatkin');
if(isset($_GET['customer_id'])){
$id=$_GET['customer_id'];
$del="DELETE FROM customers WHERE customer_id='".$id."'";
mysqli_query($connect,$del);
echo "$_GET['customer_id']";
}
?>
控制器:
$scope.delete = function(deletingId, index){
var params = $.param({"customer_id":deletingId})
$http({
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
url: "api/deleteCustomer.php?customer_id=?" + deletingId ,
method:"GET",
data:params
}).success(function(data){
$scope.customers.splice(index,1);
console.log(data);
});
答案 0 :(得分:0)
使用以下
更改您的$ del$del="DELETE FROM customers WHERE customer_id=".$id;
答案 1 :(得分:0)
删除data:params
,您已经在网址
$scope.delete = function(deletingId, index){
$http({
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
url: "api/deleteCustomer.php?customer_id=" + deletingId ,
method:"GET"
}).success(function(data){
$scope.customers.splice(index,1);
console.log(data);
});
答案 2 :(得分:0)
$del="DELETE FROM customers WHERE customer_id='$id'";
使用上面的行
更改 $ del