I another issue with MySQL (if you were following my last post I have decided to scrap inputting and focus on selecting for now).
I have been following a youtube tutorial on how to display data from my database on my php page. The following code is EXACTLY what he has given me.
However I'm sure the problem lies somewhere in connecting to the database, because if I remove everything other than that the connection code I still get the same problem.
When I load the page it just goes blank.
On Youtube when he loads the page he gets his results.
I've gone over my username, password and DB name 100 times and they are correct.
Can anyone see any problems with the following code?
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php
$servername = "localhost";
$username = "cbdadmin";
$password = "XXXX";
$dbName = "cbd_players";
//create connection
$conn = new mysqli($servername, $username, $password, $dbName);
// check connection
if (conn -> connect_error) {
die ("connection failed: " . $conn -> connect_error);
}
$sql = "SELECT * FROM 'results'";
$result = $conn ->query($sql);
if ($result-> unm_rows > 0) {
echo "<table> <tr><th>Home Team</tr></th> <tr><th>Home Score</tr></th> <tr><th>Away Score</tr></th> <tr><th>Awa Team</tr></th> <tr><th>Venue</tr></th>";
while($row = $result -> fetch_assoc()){
echo "<tr><td>" . $row["hometeam"] . "</td> <td>" . $row["homescore"] . "</td> <td>" . $row["awayteam"] . "</td> <td>" . $row["awayscore"] . "</td> <td>" . $row["venue"] . "</td></tr>";
}
echo "</table>";
}
else {
echo "No game have yet been played.";
}
$conn->close();
?>
<p>Test</p>
</body>
</html>
http://localhost/(or your hosted site URL), or asfile:///? What's the file's extension,.phpor.html? I can't see your code failing otherwise. However, you do have a syntax error hereif (conn ->where error reporting would have thrown you anundefined constant connnotice. Besides that, can't see how it would fail. You missed the$forconn ->.if ($result-> unm_rows > 0)a typo here that needs to read asif ($result-> num_rows > 0). Again; error reporting and checking with proper error handling would have helped you here. If you post the same codes again, your question may be closed by others as typos.