Error when listing bank data

1

You are giving the following error:

  

Notice: Undefined variable: report in C: \ xampp \ htdocs \ nise \ general.php   online 262

     

Warning: Invalid argument supplied for foreach () in   C: \ xampp \ htdocs \ nise \ general.php on line 262

     

Line 262 is where this code snippet is:    <?php foreach ( $denuncia as $den ) { ?>

.

    <?php 

if(!empty($_FILES['uploaded_file'])){
    $username = 'root';
    $password = '';
    $connection = new PDO( 'mysql:host=localhost;dbname=nise', $username );


    $query = "INSERT INTO resposta_denuncia (descricao_resposta, imagem, id_usuario) 
          VALUES (:descricao_resposta, :imagem, :id_usuario)";
    $statement = $connection->prepare($query);



    $path = "img_denuncia/";
    $path = $path . basename( $_FILES['uploaded_file']['name']);
    if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $path))



    $valores = array();
    $valores[':descricao_resposta'] = $_POST['descricao_resposta'];
    $valores[':imagem'] = $_FILES['uploaded_file']['name'];
    $valores[':id_usuario'] = 2;


  if(!isset($_POST['descricao_resposta']) or empty($_POST['descricao_resposta'])) {

    echo 0;

}elseif($result = $statement->execute($valores)) {

    echo 1; // dados enviados com sucesso

} else {

    echo 0; // erro ao tentar enviar dados 

}

    //criei a query
        $query = "SELECT id, data, descricao, imagem, image FROM denuncia";

        //prepara a query
        $statement = $connection->prepare($query);

        //executar o comando sql
        $result = $statement->execute();

        //juntar todos os resultados do select em um vetor de arrays
        $statement->execute();
        $denuncia = $statement->fetchAll();

    return $denuncia;

}
?>

table

<!--Começo da tabela-->
            <div class="card mb-3">
             <div id="wrapper">
                <div id="content-wrapper">
                    <div class="container-fluid">
                        <div class="card-body">
                            <div class="table-responsive">
                    <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">

                      <thead>
                        <tr>
                            <th id="id_bd">Nº</th>
                            <th id="date">Data e hora</th>
                            <th id="local">Local</th>
                            <th id="comentario">Comentário</th>
                            <th id="imagem">Imagem</th>
                        </tr>
                      </thead>


                    <?php  foreach (  $denuncia as $den )  {  ?>
                        <tr>
                          <td><?php echo $den["id"];?></td>
                          <td><?php echo $den["data"];?></td>
                          <td><?php echo $den["descricao"];?></td>
                          <td><?php echo $den["imagem"];?></td>
                          <td><?php echo $den["qual_descricao"];?></td>
                        </tr>
                    <?php } ?>


                      </table>
                  </div>
                </div>
                <div class="card-footer small text-muted">Atualizado ontem às 11:59 PM</div>
              </div>
          </div>
        </div>
        </div>
        <!--Começo da tabela-->
    
asked by anonymous 16.10.2018 / 19:11

1 answer

1

In fact, you should not use the $denuncia variable but the $result' variable.

<?php  foreach (  $result as $den )  {  ?>

$denuncia does not exist, not declared.

But the exact same would be as follows:

$statement->execute();
$denuncia = $statement->fetchAll();

// ...

<?php  foreach (  $denuncia as $den )  {  ?>

I say this because in your code, in a redundant way you are putting the variable $result to get the return of the functions execute() and fetchAll() .

    
16.10.2018 / 19:30