I am not that much of an expert in PHP as it has been few months since I started playing with it. Currently I am working on creating a basic CRUD operation in PHP. I follow this tutorial on CRUD in PHP (https://www.cloudways.com/blog/execute-crud-in-mysql-php/ ) to create it on a local wamp server. However, I am getting following error:

Fatal error: Call to a member function fetch_array () on string in C: \ wamp \ www \ crud_oop \ index.php on line 233

Can anyone point out what I am doing wrong? Here is my full code:

<div class="container"> <div style="height:50px;"></div> <div class="well" style="margin-left:auto; margin-right:auto; padding:auto; width:70%;"> <span style="font-size:25px; color:#1f1a2f"><strong>Sorteio</strong></span> <!-- BOTÕES --> <span class="pull-right"><a href="#addnewPe" data-toggle="modal" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span> Adicionar</a></span> <div style="height:15px;"></div> <table class="table table-striped table-bordered table-hover"> <thead> <th>Codigo</th> <th>Data pedido</th> <th>Cliente</th> <th>Funcionário</th> <th>Produto</th> <th>Quantidade</th> <th>Total do pedido</th> <th>Ação</th> </thead> <tbody> <?php
        $query=$conn->query("SELECT * FROM tb_pedido Pp INNER JOIN tb_cliente C ON Pp.codCliente = C.codCliente INNER JOIN tb_funcionario F ON Pp.codFuncionario = F.codFuncionario INNER JOIN tb_produto P ON Pp.codProduto = P.codProduto");
        while($row=$query->fetch_array()){
            ?> <tr> <td><?php echo $row['codPedido']; ?></td> <td><?php echo $row['dataPedido']; ?></td> <td><?php echo $row['nomeCliente']; ?></td> <td><?php echo $row['nomeFuncionario']; ?></td> <td><?php echo $row['descricao']; ?></td> <td><?php echo $row['qtdVendida']; ?></td> <td><?php echo $row['totalPedido']; ?></td> <td> <span class="pull-center"><a href="#delPp<?php echo $row['codPedido']; ?>" data-toggle="modal" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span></a></span> <p>_____</p> <span class="pull-center"><a href="#editPp<?php echo $row['codPedido']; ?>" data-toggle="modal" class="btn btn-warning"><span class="glyphicon glyphicon-edit"></span></a></span> <?php include('pedido/button.php'); ?> </td> </tr> <?php
        }

        ?> </tbody> </table> <?php
    if(isset($_SESSION['msgPp'])){
        ?> <div class="alert alert-success"> <?php echo $_SESSION['msgPp']; ?> </div> <?php
        unset($_SESSION['msgPp']);
    }
    ?> </div> <?php include('pedido/add_modal.php'); ?> 

Recommended Answers

All 2 Replies

run this query in backend phpmyadmin or any tool you have directly. You may find error there, solve and fix your query in your code.

SELECT * FROM tb_pedido Pp INNER JOIN tb_cliente C ON Pp.codCliente = C.codCliente INNER JOIN tb_funcionario F ON Pp.codFuncionario = F.codFuncionario INNER JOIN tb_produto P ON Pp.codProduto = P.codProduto

There are a few things to keep in mind when troubleshooting CRUD errors in PHP. First, check that your PHP code is syntactically correct. Then, make sure that you have the correct permissions set for your files and folders. Finally, try restarting your server. If the problem persists, please contact your host for support.
I also facing this error on my website

commented: Please be timely. 4 years is long time to answer. +16
commented: Help can never be too late as long as people are still coming across this page +34
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.