Reputation: 1
Trying to get info from the database into a table. Below is the code I am using but it is not populating the table. The site comes up but no info from the database. Please help, I am very new to this php thing and have no idea what I am doing apart from Google!
<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>
Upvotes: 0
Views: 179
Reputation: 44844
Your query is wrong
$query = "SELECT * FROM 'teacher'";
should be
$query = "SELECT * FROM `teacher`";
Upvotes: 2