試圖從數據庫中獲取信息到表中。以下是我正在使用的代碼,但它並未填充表格。該網站出現,但沒有來自數據庫的信息。請幫忙,我對這個php很陌生,不知道我在做什麼,除了Google!mysqli從數據庫中獲取信息
<body>
<?php include("header.php"); ?>
<?php
$con=mysqli_connect("localhost","username","password","database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$query = "SELECT * FROM 'teacher'";
$result = mysqli_query($con, $query);
echo "<div align=\"center\">";
echo "<table width=\"100%\">";
echo "<tr>";
echo "<th>First Name</th>";
echo "<th>Middle Name</th>";
echo "<th>Last Name</th>";
echo "</tr>";
while ($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "</td><td>";
echo $row['first_name'];
echo "</td><td>";
echo $row['middle_name'];
echo "</td><td>";
echo $row['last_name'];
echo "</td></tr>";
}
echo "</table>";
mysqli_free_result($result);
mysqli_close($con);
?>
</div>
</body>
如果你仍然在學習PHP和MySQL則是開始學習的,而不是庫MySQLi PDO是一個好主意。 – AgeDeO
^誰說的? –