I am trying to write a code to extract data from my MySQL database to a table on my website, I managed to setup a connection because it doesn't give me the failed to connect error, however the echo is just showing me the lines of code I wrote. I must have done something wrong.
The code I have:
<?php
$con=mysqli_connect("IP","username","password","db name");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "SELECT DISTINCT lastDisplayName FROM ranks ORDER BY `points` DESC LIMIT 10";
$result = $con->query($sql);
if ($result->num_rows > 0)
{
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["lastDisplayName"]. " " .$row["points"]. "<br>";
}
} else {
echo "0 results";
}
mysqli_close($con);
?>
I am a beginner and I made this code by viewing several online tutorials.
Edit: I dont really think someone has the exact same code with the exact same mistake. Thereby I do not think this question is a duplicate.
"; } } else { echo "0 results"; } mysqli_close($con); ?> – Merty123 Nov 05 '16 at 01:36