I want to display data from a database from instead of showing the data in html it tells me "Connection failed: Access denied for user ''@'localhost' (using password: NO)"
I've tried searching the problem online and when other people had the same issue it was the case where they either had 'root'@'localhost' or 'user'@'localhost'. But in my case it doesn't even show any kind of username, it's blank.
<?php
$servername = "localhost";
$username = "john";
$password = "johndoe";
$dbname = "login";
// Create connection
$conn = new mysqli($localhost, $john, $johndoe, $login);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT firstname, lastname FROM cards";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<br> id: ". $row["id"]. " - Name: ". $row["firstname"]. " " . $row["lastname"] . "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>