Notice: Undefined variable: list_book

Asked

Viewed 39 times

0

    <form class="form" method="POST"action="processa_livro.php">
                    <table class="table table-bordered">
                        <thead>
                        <tr>
                            <th>Nome</th>
                            <th>Autor</th>
                            <th>Categoria</th>
                            <th>Ação</th>
                        </tr>
                        </thead>
                        <tbody id="myTable">
                        <?php echo "<tr>"?>
                            <?php echo"<td>". $list_livro['nome']."</td>"?>
                            <?php echo"<td>". $list_livro['autor']."</td>"?>
                            <?php echo"<td>". $list_livro['categoria']."</td>"?>
                            <td>
                            <input type="image" name="submit" src="img/alter.png" value="alterar" style="width:20px;">&nbsp;&nbsp;
                            <input type="image" name="submit" src="img/deletar.png" value="deletar" style="width:20px;">
                            </td>
                        <?php echo"</tr>"?>
  </table>
</form>

php.

<?php
include_once("conexao.php");

$nome = $_POST['nome'];
$autor = $_POST['autor'];
$categoria = $_POST['categoria'];

$sql = "insert into livro (nome, autor, categoria) values ('$nome', '$autor','$categoria')";
$cadastrar = mysqli_query($conexao, $sql);


$list = "SELECT nome, autor, categoria FROM livro";
$list_livro = mysqli_query($conexao, $list);
mysqli_close($conexao);

?>

I’m taking this exit. Could someone point the way so I can be tidying up?

  • Within the body of your table you try to display data from a variable $list_livro that is not defined.

  • $list_livro only exists in the archive processa_livro.php, are you importing the file? tries to add <?php include_once('processa_livro.php') ?> before the table in html.

  • I include the $list_book variable in process_book.php. From this it would not read automatically?

  • @edsonalves This would give other errors, because the file would receive a GET request, but only treats the POST request. Maick, no, they’re different files with different scopes.

1 answer

0

This variable $list_livro only exists in the file processa_livro.php. A possible solution would be to put the query in the file that shows the table. As for example:

<?php
    include_once("conexao.php");
    $list = "SELECT nome, autor, categoria FROM livro";
    $list_livro = mysqli_query($conexao, $list);
    mysqli_close($conexao);
?>

<form class="form" method="POST"action="processa_livro.php">
    <table class="table table-bordered">
        <thead>
        <tr>
            <th>Nome</th>
            <th>Autor</th>
            <th>Categoria</th>
            <th>Ação</th>
        </tr>
        </thead>
        <tbody id="myTable">
        <?php echo "<tr>"?>
            <?php echo"<td>". $list_livro['nome']."</td>"?>
            <?php echo"<td>". $list_livro['autor']."</td>"?>
            <?php echo"<td>". $list_livro['categoria']."</td>"?>
            <td>
            <input type="image" name="submit" src="img/alter.png" value="alterar" style="width:20px;">&nbsp;&nbsp;
            <input type="image" name="submit" src="img/deletar.png" value="deletar" style="width:20px;">
            </td>
        <?php echo"</tr>"?>
    </table>
</form>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.