Getting Fatal error in php

Hi,

I am trying to resolve this issue. But couldnt do it. Please help

I am trying to view all the records in my database, but getting " Fatal error: Call to a member function query() on a non-object …" and its pointing to
[php]if ($result = $mysqli->query(“SELECT ProductName, Description, Price, Size FROM Products ORDER BY ProductID”))[/php] this line of the code.

Here is my Complete code

[php]<?php

                    include('db_connect.php');
                 
                    
                    if ($result = $mysqli->query("SELECT ProductName, Description, Price, Size FROM Products ORDER BY ProductID"))
                    {
                          
                            if ($result->num_rows > 0)
                            {
                                   
                                    echo "<table border='1' cellpadding='10'>";
                                    
                                  
                                    echo "<tr><th>ProductID</th><th>ProductName</th><th>Description</th><th>Price</th><th>Size</th></tr>";
                                    
                                    while ($row = $result_fetch_object())
                                    {
                                            
                                          echo "<tr>";
                                            echo "<td>" . $row->ProductID . "</td>";
                                            echo "<td>" . $row->ProductName . "</td>";
                                            echo "<td>" . $row->Description . "</td>";
											echo "<td>" . $row->Price . "</td>";
											echo "<td>" . $row->Size . "</td>";
                                            echo "<td><a href='records.php?ProductID=" . $row->ProductID . "'>Edit</a></td>";
                                            echo "<td><a href='delete.php?ProductID=" . $row->ProductID . "'>Delete</a></td>";
                                            echo "</tr>";
                                    }
									echo "</table>";
                            }
							else
                            {
                                    echo "No results to display!";
                            }
                    }
					else
                    {
                            echo "Error: " . $mysqli->error;
                    }
                    
                 
                    $mysqli->close();
            
            ?>[/php]

Either db_connect.php isn’t being included, or it is and the mysqli connection failed. Above the if statement, put this:

[php]var_dump($mysqli);[/php]

That should shed some light on the problem, if not report back with what you got from that and I’ll see if I can help further.

Sponsor our Newsletter | Privacy Policy | Terms of Service