0

products are inserted successfully but cant show the products from the database it doesn't shows any erro...

this is my main.html page At first there are some problems in the in the angularjs function then i change the function from Success() to then() then the value insert work but now couldn't load the data from the database and show it

<!DOCTYPE html>
<html>
<head>
<title>Office Essentials</title>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<h2>Office Essentials</h2>
<div ng-app="myApp" ng-controller="cntrl">
<form>
        Product Name:<br>
        <input type="text" ng-model="name" name="name"><br>
        Quantity:<br>
        <input type="text" ng-model="quantity" name="quantity"><br>
        Price:<br>
        <input type="text" ng-model="price" name="price"><br>
        Details:<br>
        <textarea ng-model="details" name="details"></textarea>
        <br><br>
        <input type="submit" ng-click="insertData()" value="Submit">
        <br><br>
        <input type="submit" ng-click="displayProduct()" value="Show">
        {{msg}}
</form>

this is for showing the products from the database

<table border="1">
  <tr>
    <th>Id</th>
    <th>Product Name</th>
    <th>Quantity:</th> 
    <th>Price</th>
    <th>Details</th>
    <th>Status</th>
  </tr>
  <tr ng-repeat="product in data">
    <td>{{product.id}}</td>
    <td>{{product.name}}</td>
    <td>{{product.quantity}}</td> 
    <td>{{product.price}}</td>
    <td>{{product.details}}</td>
    <td>{{product.status}}</td>
  </tr>
</table>
</div>

this is the sqript i also used in main.html page

<script >
    var app=angular.module('myApp',[]);
    app.controller('cntrl',function($scope,$http){
        $scope.insertData = function(){
            $http.post("insert.php",
            {
                'id':$scope.id,
                'name':$scope.name,
            'quantity':$scope.quantity,
            'price':$scope.price,
            'details':$scope.details
            })
            .then(function onSuccess(){
                $scope.msg = "data Inserted";
            })
        }

        $scope.displayProduct=function(){
            $http.get("select.php")
            .then(function onSuccess(data){
                $scope.data=data
            })
        }
    });
</script>

</body>
</html>

this is my select.php page

<?php
include "connectdb.php";

$query = "SELECT * FROM officeessentials";
$result=$dbhandle->query($query);

while($row = $result->fetch_assoc()){
$data[]->$row;
}

print json_encode($data);
?>

1 Answer 1

0

update following codes in select.php

<?php
include "connectdb.php";
$query = "SELECT * FROM officeessentials";
$result = $dbhandle->query($query);
$data = [];
while($row = $result->fetch_assoc()){
    $data[] = $row;
}
echo json_encode($data, true);
?>
5
  • it create only the table boxes but couldn't show the values from database Commented Apr 23, 2018 at 20:07
  • can you get the database value ??? add console.log(data) in $scope.displayProduct function inside the onSuccess(data){, and check Commented Apr 23, 2018 at 20:11
  • no its shows a fatel error. is it a query problem?? Commented Apr 23, 2018 at 20:14
  • {data: "<br />↵<b>Fatal error</b>: Cannot use [] for read…cs\Angular\select.php</b> on line <b>8</b><br /> Commented Apr 23, 2018 at 20:14
  • now i can get the database value thaks ^_^ but it couldn't show in the table.it shows an empty table Commented Apr 23, 2018 at 20:25

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.