I have a angularjs table with data gathered from a mysql database, I tried to do a angularjs function which sent a post request to the PHP file to remove the selected row but it didn't seem to work.
This is the php code to show the table and call the Angularjs removeUser function (eliminarUsuario is the removeUser function):
echo "
<div class='adminpanel'>
<table border=\"0\">
<tr>
<th translate='BUTTON_USERNAME'></th>
<th translate='BUTTON_NAME'></th>
<th translate='BUTTON_LAST_NAME'></th>
<th translate='BUTTON_ACTION'></th>
</tr>
<tr ng-repeat=\"x in dbusers | orderBy : 'Nombre' \">
<td>{{x.cod_usuario}}</td>
<td>{{x.Nombre}}</td>
<td>{{x.Apellidos}}</td>
<td>
<button name='edit' value='{{x.cod_usuario}}' class='edit fa fa-pencil' ng-click=\"debuguear('{{x.cod_usuario}}')\"></button>
<button name='eliminar' value='{{x.cod_usuario}}' ng-click=\"eliminarUsuario('{{x.cod_usuario}}')\" class='delete fa fa-remove'></button>
</td>
</tr>
</table>
</div>
";
}
I use this Angularjs function to do the $http post:
$scope.eliminarUsuario = function(user){
$http.post('https://webUrl.../eliminarusuario.php', {usu: user});
$state.go($state.current, {}, {reload: true});
};
Then it's supposed to do this in the PHP file:
require "config.php";
$con = mysqli_connect($server, $username, $password, $dbname);
$datospost = file_get_contents("php://input");
$peticion = json_decode($datospost, true);
$user = $peticion->usu;
$consulta = "DELETE FROM 'Usuario' WHERE 'cod_usuario' = '$user'";
mysqli_query($con, $consulta);
mysqli_close($con);
header('Location: https://webUrl.../index.php');