Fatal error: Call to undefined function inclue() in ...\lyb\index.php on line 2
PHP 關鍵字 拼寫錯誤:inclue → 應為 include。
<?php
// 錯誤
inclue ("config.php");
// 正確
include ("config.php");
// 或 require_once "config.php"; // 推薦:防止重複引入
?>
<?php
// config.php - 使用 PDO + 預處理防注入
$dsn = "mysql:host=localhost;dbname=guestbook;charset=utf8mb4";
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
try {
$pdo = new PDO($dsn, "root", "root", $opt);
} catch (PDOException $e) {
die("資料庫連線失敗: " . $e->getMessage());
}
?>
<?php
require_once "config.php";
$stmt = $pdo->query("SELECT * FROM content");
$rows = $stmt->fetchAll();
?>
<h1>留言本</h1>
<table border="1" align="center" cellpadding="5" cellspacing="0">
<tr><th>Name</th><th>Email</th><th>Content</th></tr>
<?php foreach ($rows as $row): ?>
<tr>
<td><?= htmlspecialchars($row['name']) ?></td>
<td><?= htmlspecialchars($row['email']) ?></td>
<td><?= htmlspecialchars($row['content']) ?></td>
</tr>
<?php endforeach; ?>
</table>
inclue 拼寫錯誤。PDO 替代已棄用的 mysql_* 函數。htmlspecialchars() 防 XSS。require_once 避免重複引入。