Problem in php code to list the recorded data in the database (beginner)

Asked

Viewed 48 times

-1

I put the bb image and the php codes below so that someone can help me because I can’t find a solution.

Error:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in D:\ANALISE E DESENVOLVIMENTO DE SISTEMAS\XAMPP INSTALADO\htdocs\teste\lista.php on line 22

Bando de dados com uma tabela e os ítens no phpmyadmin. Connection code with bb:

<?php

        $conexao=mysqli_connect("localhost", "root", "", "teste");
?>

Write code on bb:

<?php
    include("conecta.php");

    $recnome=$_GET["nome"];
    $recemail=$_GET["email"];
    $recmensagem=$_GET["mensagem"];

    mysqli_query(conexao, "insert into dados (nome, email, mensagem) values ('recnome', 'recemail', 'recmensagem')");
    //Insira na minha tabela "dados", no campo "nome", o valor de "recnome" e assim sucessivamente...

    header("location:lista.php");

?>

listing code:

<?php   
    include("conecta.php"); //Aqui estou me conectando ao banco de dados.
    $seleciona=mysqli_query($conexao, "select * from dados order by id desc");//Selecione tudo da tabela "dados" e coloque em ordem decescente.
        while($campo=mysqli_fetch_array($seleciona)){?> <!-- Laço de repetição-->
        <!--Enquanto a minha variável campo recebe cada item da matriz array "seleciona"-->
            <tr>
                <td><?=$campo["nome"]?></td>
                <td><?=$campo["email"]?></td>
                <td><?=$campo["mensagem"]?></td>
                <td align="center"><a href="editar.php?editaid=<?=$campo["id"]?>"><i class="fa fa-edit"></i></a></td>
                <td align="center"><a href="#" onclick="verifica(<?=$campo["id"]?>)"><i class="fa fa-trash"></i></a></td>
            </tr>

        <?php   }?>
  • It is not well seen here to post the table definition image. In the image it seems that the table is called "test" but in its Insert command you enter the table "data". Idem in select.

  • Right. I apologize for the image. I didn’t know. I’m new. Thank you very much. I’ll fix it right now.

1 answer

0

You are performing the Insert in the table dice, the name of the table you have is test.

The function mysqli_query returns an object of type mysqli_result in case of success is false in the fault house.

The function mysqli_fetch_array expects to receive as parameter the object mysqli_result.

Since SQL is incorrect, the wrong parameter type is being passed to mysqli_fetch_array and therefore Warning is being triggered.

The function mysqli_query returns false in case of error

mysqli_query

mysqli_fetch_array

  • Great. Thank you. I’ll fix it right now. Thank you.

Browser other questions tagged

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