我正在嘗試解決此問題。但無法做到這一點。請幫助在php中出現致命錯誤
我想在我的數據庫,查看所有的記錄,但獲得「致命錯誤:調用一個成員函數查詢()非對象....上」,其指向
if ($result = $mysqli->query("SELECT ProductName, Description, Price, Size FROM Products ORDER BY ProductID"))
這裏是我的完整代碼
<?php
include('db_connect.php');
**$mysqli = new mysqli("localhost", "netelmbn", "password", "netelmbn");
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}**
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();
?>
只是'var_dump($ mysqli);'並找出它爲什麼不是一個對象。這可能是'假'btw。 –
嘗試定義全局結果$並檢查。 –