Difficulty updating data with angular and php

3

Good afternoon

I'm trying to update data in the database and I can not. If I use mysqli, the following warning appears on the console: " link 500 (Internal Server Error)"

If I use connection with mysql and PDO, nothing happens, no warning in the console appears.

My js file:

app.controller("AtualizarUsuarioController", function ($scope, $window, $http, $location) {

$scope.usuario = {
    'id': $window.localStorage.getItem('idUsuarios'),
    'nome': $window.localStorage.getItem('nome'),
    'email': $window.localStorage.getItem('email')
}

//$location.path('/atualizarUsuario' + $scope.usuario.id);
$scope.atualizarUsuario = function (usuario) {
    $http.post("admin/php/atualizarUsuario.php", usuario).then(function (data){
        $location.path("#/usuarios");
    });
};
});

php:

<?php
header("Access-Control-Allow-Origin: *");

include_once ("conPDO.php");
$pdo = conectar();

$postdata = file_get_contents("php://input");
$data = json_decode($postdata);
$id = $data->id;
$nome = $data->nome;
$email = $data->email;
$senha = $data->senha;

$senha = sha1($senha);

$usuarioAtual=$pdo->prepare("UPDATE usuarios SET nome=:nome, email=:email, senha=:senha WHERE id=:id");
$usuarioAtual->bindValue(":nome", $nome);
$usuarioAtual->bindValue(":email", $email);
$usuarioAtual->bindValue(":senha", $senha);
$usuarioAtual->bindValue(":id", $id);
$usuarioAtual->execute();

And my folder structure.

Returnoftheconsoleafterprint_randconsole.log

    
asked by anonymous 09.01.2016 / 18:44

1 answer

1

Your problem may be in the method used with $http , in your case you are using PUT . In the past I had problems using it too because there are configurations and (some cases) server limitations that prevent PUT from being called.

Use POST , aside from some particularities - that will not imply in your case - you will not have a problem and it might solve it.

$http.post([url], [data], [config]);

Note: Do not use print screen of your code, use the same code.

Edited:

Another important point would be to use print_r (in php) and console.log (in Angular) to better debug what is happening and where the problem is.

//No AngularJs
$scope.atualizarUsuario = function (usuario) {
    $http.post("admin/php/atualizarUsuario.php", usuario).then(function (data){
        console.log(data); //'data' pois é o valor definido dentro do 'function' do 'then'
        $location.path("#/usuarios");
    });
};

//E no PHP
$usuarioAtual->execute();
print_r($usuarioAtual);

So you have a better view of what's happening.

    
11.01.2016 / 10:47