Ошибка типа: не удается прочитать свойство из базы данных SQL - PullRequest
0 голосов
/ 26 мая 2018

Я только начал работать в angularJS, и вроде как мне это удалось, но я не могу читать из своей базы данных, когда возвращаю данные с помощью файлов php (соединение с сервером проверено и проверено дважды)не может распознать объект со всеми переменными в нем (данные) Вот полная ошибка:

ОШИБКА TypeError: Невозможно прочитать свойство 'first_name' из undefined в Object.eval [как updateRenderer] (AppComponent.html: 26) в Object.debugUpdateRenderer [as updateRenderer] (core.js: 11940) в checkAndUpdateView (core.js: 11312) в callViewAction (core.js: 11548) в execComponentViewsAction (core.js: 11490) в checkAndUpd.js: 11313) в callWithDebugContext (core.js: 12204) в Object.debugCheckAndUpdateView [as checkAndUpdateView] (core.js: 11882) в ViewRef_.push ../ node_modules/@angular/core/fesm5/cef.jView.detectChanges (core.js: 9692) в core.js: 5086 View_AppComponent_0 @ AppComponent.html: 26

Вот мой полный основной HTML-файл:

<html>  
      <head>  
           <title>Webslesson Tutorial | AngularJS Tutorial with PHP - Fetch / Select Data from Mysql Database</title>  
           <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  
           <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>  
      </head>  
      <body>  
           <br /><br />  
           <div class="container" style="width:500px;">  
                <h3 align="center">AngularJS Tutorial with PHP - Fetch / Select Data from Mysql Database</h3>  
                <div ng-app="myapp" ng-controller="usercontroller" ng-init="displayData()">  
                     <label>First Name</label>  
                     <input type="text" name="first_name" ng-model="firstname" class="form-control" />  
                     <br />  
                     <label>Last Name</label>  
                     <input type="text" name="last_name" ng-model="lastname" class="form-control" />  
                     <br />  
                     <input type="submit" name="btnInsert" class="btn btn-info" ng-click="insertData()" value="ADD"/>  
                     <br /><br />  
                     <table class="table table-bordered">  
                          <tr>  
                               <th>First Name</th>  
                               <th>Last Name</th>  
                          </tr>  
                          <tr ng-repeat="x in names">  
                               <td>{{x.first_name}}</td>  
                               <td>{{x.last_name}}</td>  
                          </tr>  
                     </table>  
                </div>  
           </div>  
      </body>  
 </html>  
 <script>  
 var app = angular.module("myapp",[]);  
 app.controller("usercontroller", function($scope, $http){  
      $scope.insertData = function(){  
           $http.post(  
                "insert.php",  
                {'firstname':$scope.firstname, 'lastname':$scope.lastname}  
           ).success(function(data){  
                alert(data);  
                $scope.firstname = null;  
                $scope.lastname = null;  
                $scope.displayData();  
           });  
      }  
      
      $scope.displayData = function(){  
           $http.get("select.php")  
           .success(function(data){  
        
                $scope.names = data;  
                
           });  
      }  
 });  
 </script>  
<pre>

<!-- begin snippet: js hide: false console: true babel: false -->

Также вот мой select.php:

<?php  
 //select.php  
 $connect = mysqli_connect("den1.mssql5.gear.host", "testiranje", "nijebitno@", "testiranje");  
 $output = array();  
 $query = "SELECT * FROM dbo.tbl_user";  
 $result = mysqli_query($connect, $query);  
 if(mysqli_num_rows($result) > 0)  
 {  
      while($row = mysqli_fetch_array($result))  
      {  
           $output[] = $row;  
      }  
      echo json_encode($output);  
 }  
 ?>
...