我正在使用angular和php构建项目。我有一个"文件"我的数据库中的表,我可以发送文件并检索我需要的所有信息。我添加了一个删除按钮,但我不知道它为什么不起作用。我的控制台没有错误。有人可以看看我的代码吗?
php for deleteing:
<?php
header('Content-Type: text/html; charset=utf-8');
$connect = mysqli_connect("localhost", "root", "", "hamatkin");
include_once 'file.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();
$data = json_decode(file_get_contents("php://input"));
$x = $data->reffer_customer_id;
$reffer_customer_id = $data->reffer_customer_id;
$del = "DELETE FROM file WHERE reffer_customer_id = " . $reffer_customer_id;
//echo $del;
mysqli_query($connect, $del);
$newURL = "/hamatkin/#/allPriceOffers";
header('Location: '.$newURL);
?>
控制器:
$scope.delete = function(deletingId, $index) {
$http.post('api/customers-tab/delete-priceOffer.php', { "reffer_customer_id" : deletingId })
.success(function(data) {
var arr = JSON.parse(JSON.stringify(data));
$scope.files = arr;
var arr2 = arr.split(",");
arr2.splice($index, 1);
$route.reload();
});
};
Html删除按钮:
<td><a ng-click="delete(x.reffer_customer_id, $index)" class="btn btn-primary btn-active">מחיקה</td>
答案 0 :(得分:0)
首先,您应该修复HTML:
ng-click
属性上添加删除功能是什么意思,可能你想用on-click
代替?如果我错了,请纠正我<a>
代码,但</a>
缺席 <td>
中的已更正HTML按钮是:
<td><a on-click="delete(x.reffer_customer_id, $index); return false;" class="btn btn-primary btn-active">מחיקה</a></td>
在第二步中,我建议检查表file
的MySQL方案,并确保提供相同类型的refferal_customer_id
。
例如,我想知道这应该是数值,而不是:
<?php
header('Content-Type: text/html; charset=utf-8');
/*
* I propose to check all data before you will open connection to MySQL,
* because if data is not correct - connection will not be used
* I strongly propose to process errors in your client scripts
*/
$data = json_decode(file_get_contents("php://input"));
if (!isset($data) ||
!isset($data->reffer_customer_id) ||
!is_numeric($data->reffer_customer_id)
) {
echo 'Incorrect data specified';
exit;
}
/*
* Connecting
*/
$connect = mysqli_connect("localhost", "root", "", "hamatkin");
/*
* I don't know why you using it for delete query if your id is numeric
*/
mysqli_query($connect, "SET character_set_client = utf8");
mysqli_query($connect, "SET character_set_connection = utf8");
mysqli_query($connect, "SET character_set_results = utf8");
/*
* I don't recommend you to pass mysql connection error in raw format,
* because it can be used against you
* And don't forget to halt your script if error occurred
*/
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL";
exit;
}
/*
* Here your delete query
*/
$delId = mysqli_real_escape_string($connect, $data->reffer_customer_id);
if (!$delId) {
echo 'Incorrect id for delete query specified';
exit;
}
/*
* Don't forget to check errors
*/
if (!mysqli_query($connect, "DELETE FROM file WHERE reffer_customer_id = $delId")) {
echo "Failed to delete reffer_customer with id: $delId";
exit;
}
/*
* And close the connection
*/
mysqli_close($connect);
/*
* As for me: better to put next route into response for redirecting from client
* but I don't know what you will do with this, so, putting header
*/
header('Location: /hamatkin/#/allPriceOffers');
答案 1 :(得分:-2)
我认为你的查询应该是这样的:
$del = "DELETE FROM file WHERE reffer_customer_id=".$reffer_customer_id." ";