Error in JSON object in php

Asked

Viewed 51 times

0

there was some modification when creating or picking up a JSON object in PHP?

I have the following code:

Angular:

$scope.atualizaUsuario = function(usuario) {
    $window.localStorage.setItem("nome", usuario.nome);
    $window.localStorage.setItem("usuario", usuario.usuario);
    $window.localStorage.setItem("email", usuario.email);

    var nome = $window.localStorage.getItem("nome", nome);
    var usuario = $window.localStorage.getItem("usuario", usuario);
    var email = $window.localStorage.getItem("email", email);
    var idUsuario = $window.localStorage.getItem("idUsuario", idUsuario);

    usuario = {
        "idUsuario":idUsuario,
        "nome":nome,
        "usuario":usuario,
        "email":email
    }

    $http.put("http://www.vigilantescomunitarios.com/php/atualizaUsuario.php", usuario).success(function (data){
        console.log(data);
        $location.path("/ajustes");
    })
}

Afterward...

<?php
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);

$idUsuario = $request->idUsuario;
$name = $request->name;
$usuario = $request->usuario;
$email = $request->email;
$pass = $request->pass;

I ask this question, because in php logo appears this message: inserir a descrição da imagem aqui

Does anyone know why? Thanks.

  • Have you tried giving a print_r($request) to see what you print? I saw that you are making $request->name but I believe that the right is $request->name I think that already solves the fatal error, but give a print_r after Code to see how the object is getting. After the print puts die;

  • I discovered the problem @Andrévicente. I had not created the json object, as put in the post update. Thanks.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.