我無法弄清楚為什么我的代碼不起作用?當我運行它時,頁面是空白的!
這是一個哈利波特資料庫。我正在嘗試將我的 SQL 資料庫中的資料放在 HTML 表中。聽起來很簡單,但我不知道為什么我的代碼不起作用!
<!DOCTYPE html>
<html>
<head>
<title> Harry Potter Database </table>
</head>
<body>
<table>
<tr>
<th> ID </th>
<th> Name </th>
<th> Age </th>
<th> Website </th>
</tr>
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1); error_reporting(E_ALL);
$conn = mysqli_connect("localhost", "root", "", "survey");
$sql = "SELECT * FROM result";
$res = $conn->query($sql);
if($res->num_rows > 0)
{
while($row = $res->fetch_assoc())
{
echo "<tr>
<td>". $row["ID"] . "</td>
<td>". $row["Name"] . "</td>
<td>". $row["Age"] . "</td>
<td>". $row["Website"] . "</td>
</tr>";
}
}
else{
echo "No RESULTS";
}
$conn->close();
?>
</table>
</body>
</html>
結果是我的資料庫中名為調查的名稱資料
第26行C:\xampp\htdocs\ws5\sqlquery.php中未定義的陣列鍵“ID”
這是源中的錯誤
表結構
| ID | 網站 | 年齡 | 網站 |
|---|
uj5u.com熱心網友回復:
在 Windows 上(看起來像你),默認情況下 MySQL 以小寫形式存盤所有表和列名(請參閱“識別符號大小寫敏感度”的檔案和lower_case_table_names)。
這意味著"ID"您應該使用"id",而不是"Name"應該使用"name",等等。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/443824.html
下一篇:獲取有帖子的用戶
