1

This is the database that is interacting with Android App also.

My other database tables data are working but one of the table is not able to be fetched on the HTML page.

Database with tables problem in order

Table order structure

Error

Error: Trying to get property of non-object in C:\xampp\htdocs\tutorial\trydata01\testt.php on line 39 0 result

PHP CODE:

<!DOCTYPE html>
<html>
<head>
    <title>Table with database</title>
    <style type="text/css">
        table {
            border-collapse: collapse;
            width: 100%;
            color: #d96459;
            font-family: monospace;
            font-size: 25px;
            text-align: left;
        }
        th{
            background-color: #588c7e;
            color: white;
        }
    </style>
</head>
<body>
    <table>
        <tr>
            <th>OrderId</th>
            <th>OrderStatus</th>
            <th>OrderPrice</th>
            <th>OrderDetail</th>
            <th>OrderComment</th>
            <th>OrderComment1</th>
            <th>UserPhone</th>
        </tr>
        <?php 
        $conn = mysqli_connect("localhost", "root", "", "wcfood01");
        if ($conn-> connect_error) {
            die("Connection failed:". $conn-> connect_error );
        }
        $sql = "SELECT * from order";
        $result = $conn-> query($sql);

        if ($result-> num_rows > 0) {
            while ($row = $result-> fetch_assoc()) {
                echo "<tr><td>". $row["OrderId"] ."</td><td>". $row["OrderStatus"] ."</td><td>". $row["OrderPrice"] . "</td><td>". $row["OrderDetail"] . "</td><td>". $row["OrderComment"] ."</td><td>". $row["OrderComment1"] ."</td><td>". $row["UserPhone"] ."</td></tr>";
            }
            echo "</table>";
        }
        else{
            echo "0 result";
        }

        $conn-> close();
        ?>
    </table>

</body>
</html>
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 1
    What do `$conn-> connect_error` or `$conn-> query` do, where are they defined? – brombeer Nov 28 '19 at 12:21
  • 1
    Please read: [Should we ever check for mysqli_connect() errors manually?](https://stackoverflow.com/q/58808332/1839439) You are not checking for connection errors properly, and in fact you do not need to do so. – Dharman Nov 28 '19 at 18:52

1 Answers1

0

Romove the space between object and function :

$conn-> connect_error
$conn-> connect_error
$result-> num_rows
$result-> fetch_assoc()

Changes :

$conn->connect_error
$conn->connect_error
$result->num_rows
$result->fetch_assoc()

HTML :

<!DOCTYPE html>
    <html>
    <head>
        <title>Table with database</title>
        <style type="text/css">
            table {
                border-collapse: collapse;
                width: 100%;
                color: #d96459;
                font-family: monospace;
                font-size: 25px;
                text-align: left;
            }
            th{
                background-color: #588c7e;
                color: white;
            }
        </style>
    </head>
    <body>
        <table>
            <tr>
                <th>OrderId</th>
                <th>OrderStatus</th>
                <th>OrderPrice</th>
                <th>OrderDetail</th>
                <th>OrderComment</th>
                <th>OrderComment1</th>
                <th>UserPhone</th>
            </tr>
            <?php 
            $conn = mysqli_connect("localhost", "root", "", "wcfood01");
            if ($conn->connect_error) {
                die("Connection failed:". $conn->connect_error );
            }
            $sql = "SELECT * from order";
            $result = $conn->query($sql);

            if ($result->num_rows > 0) {
                while ($row = $result->fetch_assoc()) {
                    echo "<tr><td>". $row["OrderId"] ."</td><td>". $row["OrderStatus"] ."</td><td>". $row["OrderPrice"] . "</td><td>". $row["OrderDetail"] . "</td><td>". $row["OrderComment"] ."</td><td>". $row["OrderComment1"] ."</td><td>". $row["UserPhone"] ."</td></tr>";
                }
                echo "</table>";
            }
            else{
                echo "0 result";
            }

            $conn-> close();
            ?>
        </table>

    </body>
    </html>
Ramki
  • 452
  • 2
  • 16