1

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');
  • `$peticion` will be an array not an object, also see [When to use single quotes, double quotes, and back ticks in MySQL](https://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-back-ticks-in-mysql) – Lawrence Cherone Mar 02 '18 at 17:58
  • If you make `var_dump` in the $datospost, what it is output? – Jose Rojas Mar 02 '18 at 20:26

0 Answers0