0

I have MySQL server installed and I have created a test database named "test" and done a simple login example, with the ID, username, password and email. According to W3Schools, I have modified the code they provide:

<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
     border: 1px solid black;
}
</style>
</head>
<body>

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
     die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT id, username, password, email FROM user";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
     echo "<table><tr><th>ID</th><th>Username</th><th>Password</th><th>Email</th></tr>";
     // output data of each row
     while($row = $result->fetch_assoc()) {
         echo "<tr><td>" . $row["id"]. "</td><td>" . $row["username"]. "</td><td>" . $row["password"]. "</td><td>" . $row["email"]. "</td></tr>";
     }
     echo "</table>";
} else {
     echo "0 results";
}

$conn->close();

?>

</body>
</html>

I've searched the directory of the database and I see in C:\Program Files\MySQL\MySQL Server 5.6\data a folder named "test" that contains 3 files, a .opt file, a .frm and a .ibd.

My question is, where should I put the html file in order to load this database data? Or should I change something from my code? Thanks!

10
  • 1
    HTML files always go in the web server root. Jun 26, 2015 at 21:15
  • I've placed the html in C:\Program Files\MySQL\MySQL Server 5.6. If I open the html with the web browser it does not load the file. How should I open it or what am I doing wrong? Thanks! Jun 26, 2015 at 21:37
  • Are you running a webserver? Jun 26, 2015 at 21:39
  • I have configured the Apache server in localhost and the MySQL server I think it is by default at 3036 port if that's what you are asking Jun 26, 2015 at 21:47
  • Look in your Apache folder - there should be a www/ or htdocs/ or something that is the root web server folder. All your HTML shoulld go there until you learn how to modify directives. Jun 26, 2015 at 21:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.