1
I am trying to make a method to delete a record from the bank and the following message seems on the console:
GET http://localhost:8888/systems/systems_web/Vigilantescomunitarios/admin/php/apagaPais.php? idPais=Undefined 500 (Internal Server Error)
I’m using angular ui-router.
Follow my codes:
html:
<table width="200">
<tr>
<td><b>País</b></td>
<td><b>Sala</b></td>
</tr>
<tr ng-repeat="pais in paises">
<td>{{pais.nome}}</td>
<td>{{pais.sala}}</td>
<td><a ui-sref="editarPais({idPais: pais.idPais})">[ ]</a></td>
<td><a ng-click="apagarPais(pais.idPais)">[x]</a></td>
</tr>
</table>
Angular:
app.controller("PaisesController", function ($scope, $http, $stateParams, $state) {
$scope.apagarPais = function (pais) {
console.log("id "+pais);
$http.get("admin/php/apagaPais.php?idPais="+pais)
.success(function (data, status){
console.log(data);
carregaPaises();
});
};
carregaPaises();
});
php:
include_once("conexao.php");
$pdo = conectar();
$id = $_POST['idPais'];
print_r($id);
$apagaPais=$pdo->prepare("DELETE FROM paises WHERE idPais=:id");
$apagaPais->bindValue(":id", $id);
$apagaPais->execute();
I made the changes and the message continues. "POST http://localhost:8888/systems/systems_web/Watchersmunitarios/admin/php/apagaPais.php? idPais=Undefined 500 (Internal Server Error)" .
– GustavoSevero
As I have already answered in other questions of yours, use the print and console methods. This error by itself says it all, there was some internal error of the server, not having connection with the angular. The $id is really getting the correct value?
– celsomtrindade
Had already placed console and print_r. The console, shows the id being passed. Already print_r does not return anything. I put in the code, here of the post, the consoles and prints I put in my code to see what returns. Only the first console that shows the id, the print does not appear.
– GustavoSevero
I was able to pass the id as parameter, see how I did the code update, here in the post. .
– GustavoSevero
I got it. I was doing include with wrong connection file.
– GustavoSevero
Yes, I was finding strange the server error, usually if it is error in the angular, it comes with a link to the site of the angular itself, where it contains a description of what may be happening. But if you can solve it, great! = D
– celsomtrindade