Carter Langley
Carter Langley

Reputation: 1

mysqli to get info from database

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

Answers (3)

Nagaraj S
Nagaraj S

Reputation: 13474

Try this

$query = "SELECT * FROM teacher";

Upvotes: 0

Alan Piralla
Alan Piralla

Reputation: 1196

"SELECT * FROM teacher"

Just remove your quotation marks.

Upvotes: 1

Abhik Chakraborty
Abhik Chakraborty

Reputation: 44844

Your query is wrong

$query = "SELECT * FROM 'teacher'";

should be

$query = "SELECT * FROM `teacher`";

Upvotes: 2

Related Questions