Error generating table data

0

My front does not get the data to list. But the data is inserted perfectly. How to solve?

<?php

require_once 'vendor/autoload.php';

$app = new \Slim\Slim();

$db = new mysqli("localhost","root","","neppo");

$app->get("/cadastro",function() use($db,$app) {
    $query = $db->query("SELECT * FROM cadastro");
    $cadastro = array();
    while($fila=$query->fetch_assoc()){
        $cadastro[]=$fila;
    }

    echo json_encode($cadastro);
});

/*link =  aqui se ve os dados  http://localhost/slim/api.php/cadastro */

$app->post("/cadastro",function() use($db,$app){

    $query="INSERT INTO cadastro VALUES(NULL,"
    . "'{$app->request->post("nome")}',"
    .         "'{$app->request->post("data")}',"
    .         "'{$app->request->post("cpf")}',"
    .         "'{$app->request->post("sexo")}',"
    .         "'{$app->request->post("endereco")}'"
    .     ")";
    $insert = $db->query($query);

    if($insert){
        $result = array("STATUS" => "true", "message" => "Cadastro Realizado Corretamente!!!");
    }else{
        $result = array("STATUS" => "false", "message" => "Cadastro não realizado corretamente!!!");
    }

    echo json_encode($result);

});


$app->run();
<!DOCTYPE html>
<html lang="pt">

  <head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Freelancer - Start Bootstrap Theme</title>

    <!-- Bootstrap core CSS -->
    <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom fonts for this template -->
    <link href="vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link href="https://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet" type="text/css">
    <link href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic" rel="stylesheet" type="text/css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script><script>JSON.parse=JSON.parse||function(str){if(str==="")
            str = '""';
          eval("var p="+ str +";");
          return p;
      };

      $(document).ready(function(){
         function getCadastro(){
             $.ajax({
               url: "http://localhost/neppo/slim/api.php/cadastro",
               type: "get",
               success: function(response) {
                 $.each(JSON.parse(response), function(i, index){
                   if (index.id.lenght){
                     $(".table").append("<tr><td>"+ index.id +"</td>"+
                                        "<td>"+ index.nome +"</td>"+
                                        "<td>"+ index.data +"</td>"+
                                        "<td>"+ index.cpf +"</td>"+
                                        "<td>"+ index.sexo +"</td>"+
                                        "<td>"+ index.endereco+"</td>"+
                                        "<td><span class='delete btn btn-danger' data-cadastro='"+index.id+"'>Apagar</span></td>"+
                                        "<td><span class='update btn btn-warning' data-cadastro='"+index.id+"'>Editar</span></td>"+
                                        "</tr>");

                                  }

                    });
                  }
                });
              }
         getCadastro();
  });

 </script>

  </head>

        <!-- Contact Section -->
        <section id="cadastro">
            <div class="container">
              <h2 class="text-center text-uppercase text-secondary mb-0">Cadastre</h2>
              <hr class="star-dark mb-5">
              <div class="row">
                <div class="col-lg-8 mx-auto">

                  <form action="http://localhost/neppo/slim/api.php/cadastro" method="post" data-producto="0">

                    Nome:
                    <input type="text" id="name_form" name="nome" class="form-control"/></br>

                    Data:
                    <input type="text" id="data_form" name="data" class="form-control"/></br>  

                    CPF:
                    <input type="text" id="data_cpf" name="cpf" class="form-control"/></br>

    
asked by anonymous 20.12.2017 / 17:35

0 answers