0

I have an error displayed when I run the code. The output should display a form where a user can fill their room hotel booking details in the form. The error line : while ($row_price = $Found->fetch_assoc()) Error : Fatal error: Uncaught Error: Call to a member function fetch_assoc() on boolean...

<body>
    <?php
    
    $host = "localhost";
    $dbUsername = "xxxx";
    $dbPassword = "xxxx";
    $dbname = "webmates";
    $conn = new mysqli($host, $dbUsername, $dbPassword, $dbname);

    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);}

    $LOAD = "SELECT * FROM order_food";
    $Found = $conn->query($LOAD);

    while ($row_price = $Found->fetch_assoc())
    {
        $id[]=$row_price['ID'];
        $dishes[]= $row_price['food_name'];
        $quantity[]=$row_price['quantity'];
        $serve[]=$row_price['serve'];
        $date[]=$row_price['date'];
    }

    $conn->close();
    ?>

    <form name="frmCashier" action="backupsales.php" method="POST">
    <table style="margin-left: auto;margin-right: auto;  font-family: 'Open Sans', sans-serif;background-color: lightgreen;"frame="void" rules="all">
        <caption id="username">Lists of Ordered Meals</caption>
        <tr>
            <th>ID</th>
            <th>Food Name</th>
            <th>Quantity</th>
            <th>Serve</th>
            <th>Date</th>
        </tr>
        <?php
        for ( $i = 0; $i < count( $id ); $i++ ) {
            print "<tr>";
            print "<td> $id[$i] </td>";
            print "<td> $dishes[$i] </td>";
            print "<td align='center'> $quantity[$i] </td>";
            print "<td align='center'> $serve[$i] </td>";
            print "<td> $date[$i] </td>";
            print "</tr>";
        }
        ?>
        <tr>
            <th colspan="5" align="center">
            <input type="submit" value="Backup"></input>
            </th>
        </tr>

    </table>

</body>

May I know what went wrong with the code?

Dharman
  • 26,923
  • 21
  • 73
  • 125
Anis Amira
  • 41
  • 6

0 Answers0