Click here to Skip to main content
14,494,314 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello I am new here and I really need help if something is wrong in the question let me know and I will fix it. Well I'm trying to display all registered tables on a screen of my website and I'm not getting it, I'm using the MVC model so I need an orientation for me to know if I'm doing it right or not. I'm going to send all the classes I'm using for list and the html I use.

HTML Perfil.php

<form name="formcad" class="needs-validation"  novalidate method="POST" action="PHP/Classes/ListarReserva.php">
<button class="tablink" onclick="openPage('VerReservas', this, 'chocolate')" >Ver Reservas</button>
</form>

<div id="VerReservas" class="tabcontent">

I wish that when he entered this Ver Reservation he could directly display the registered reservations
  
</div>


I wish that when he entered this Ver Reservation he could directly display the registered reservations

ListarReserva.php

<?php

include 'ReservaDAO.php';
include 'Reserva.php';


$Reserva = new Reserva();

$ReservaDAO = new ReservaDAO();
$ReservaDAO->ListarReservas($Reserva);

?>



ReservaDAO.php

 public static function ListarReservas($Reserva)
    {
        $connection = Connection::getConexao();
        $sql = "SELECT * FROM reserva";
        // Listar Todas as reservas
        $result = mysqli_query($connection, $sql);
        $reservas = array();
        while ($reserva = mysqli_fetch_object($result)) {
            if ($reserva != null) {
                $reservas[] = $reserva;
            }
        }
        return $reservas;
    }
?>


Connection.php

<?php

include 'ReservaDAO.php';
include 'Reserva.php';


$Reserva = new Reserva();

$ReservaDAO = new ReservaDAO();
$ReservaDAO->ListarReservas($Reserva);

?>


If you need any more data let me know and I'll post it here ok.

What I have tried:

I just tried to give a basic selection for him to display but he does not display and keeps giving this error:


Warning: mysqli_query() expects parameter 1 to be mysqli, object given in C:\wamp64\www\Rapid\PHP\Classes\ReservaDAO.php on line 30


Warning: mysqli_fetch_object() expects parameter 1 to be mysqli_result, null given in C:\wamp64\www\Rapid\PHP\Classes\ReservaDAO.php on line 32
Posted
Updated 25-Mar-20 13:19pm

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Connection::getConexao() method returns an object where it shoud have returned a mysqli. You did not show the definition of this method.
PHP mysqli connect() Function[^]

The second error message will probably disappear once the first error has been resolved.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100