I code my php code in another .php file and i need it to be included in the html file to retrieve the information from my database and paste it into a table.
So in other words i want my .php to be included so it will show the info
I tried using <?php include 'database.php';?>
But it doesnt seem to work
HTML:
<body>
<button class="dbknapp" onclick="window.location.href = 'index.html';">Klikk her for å legge inn informasjon!</button><br><br>
<table>
<tr>
<th>Id</th>
<th>Fornavn</th>
<th>Etternavn</th>
<th>Email</th>
</tr>
</table>
<?php include 'database.php';?>
</body>
PHP:
<?php
$servername = "localhost";
$database = "db";
$username = "root";
$password = "philip123";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $database);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT id, name, lastname, email FROM Students"
$result = $conn-> query($sql);
if ($result-> num_rows > 0) {
while ($row = $result-> fetch_assoc()) {
echo "<tr><td>". $row["id"] ."</td><td>". $row["name"] ."</td><td>". $row["lastname"] ."</td><td>". $row["email"] ."</td></tr>";
}
echo "</table>";
}
else {
echo "0 results";
}
$conn-> close();
?>