未定义的属性:stdClass :: $ id

时间:2016-10-19 08:04:25

标签: php angularjs

我和anguarjs做了一个CRUD。但更新错误。错误是:

  

未定义的属性:stdClass :: $ id in   C:\ XAMPP \ htdocs中\ crud_login \数据\ update.php

谁能帮帮我?我是angularjs的新人

控制器:

$scope.edit = function(index){
        //var index = getSelectedIndex($index);
        $scope.listData.nama = $scope.dataList[index].nama;
        $scope.listData.alamat = $scope.dataList[index].alamat;
    }
$scope.update = function(){
        $http.post(
            'data/update.php',
            {
                id: $scope.idChanged,
                data: $scope.listData
            }
        ).success(function(data){
            alert(data);
            $scope.getData();
            $scope.aksi = "add";
        }).error(function(){
            alert("Gagal mengubah data");
        });
    };

update.php:

<?php

    include 'koneksi.php';

    $postdata = file_get_contents("php://input");
    $dataObjek = json_decode($postdata);

    $id = $dataObjek->id;
    $nama = $dataObjek->data->nama;
    $alamat = $dataObjek->data->alamat;

    $query = "update listdata set nama = '{$nama}',alamat='{$alamat}' where id = {$id} ";

    $result = mysqli_query($koneksi,$query);

    $respon = "";
    if($result){
        $respon = "Berhasil menyimpan data";
    }else{
        $respon = "Gagal menyimpan data";
    }

    echo $respon;

?>

观点:

    <h2 align="center">Edit Data</h2>
    <form class="form-horizontal">
  </div>
  <div class="form-group">
    <label class="control-label col-sm-2" for="nama">Nama:</label>
    <div class="col-sm-10"> 
      <input type="text" class="form-control" ng-model="listData.nama">
    </div>
  </div>
  <div class="form-group">
    <label class="control-label col-sm-2" for="alamat">Alamat:</label>
    <div class="col-sm-10"> 
      <input type="text" class="form-control" ng-model="listData.alamat">
    </div>
  </div>
  <div class="form-group"> 
    <div class="col-sm-offset-2 col-sm-10">
      <button type="button" class="btn btn-danger" ng-click="update()">Update</button>
    </div>
  </div>
</form>

0 个答案:

没有答案