Witam,
Chciałbym aby na stronie zostały wypisane dane z bazy danych, lecz nie chce umieszczać kodu php w htmlu tylko korzystać z innego pliku.
Kod PHP:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "visitors";
$connection = new mysqli('localhost', 'root', '', 'visitors');
if ($connection->connect_error) {
die("Connection failed: " . $connection->connect_error);
}
$sql = "SELECT imie, nazwisko FROM visitors";
$result = $connection->query($sql);
echo"
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
";
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "
</tr>
<tr>
<td>" . $row["imie"] . "</td>
<td>" . $row["nazwisko"] . "</td>
</tr>
</table>
";
}
} else {
echo "0 results";
}
$connection->close();
?>
Oraz kod html:
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="newcss2.css">
<link href='http://fonts.googleapis.com/css?family=Anonymous+Pro&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<script type="text/javascript" src="test.js"></script>
</head>
<body onload="odliczanie();">
<div class="visitor">
<form action="newfile.php" method="POST">
Imie <input type="text" name="pole1x">
Nazwisko <input type="text" name="pole2x"> <br>
<input class="mainbutton" type="submit" value="DODAJ UZYTKOWNIKA">
</form>
</div>
<section id="main">
<form action="newfile2.php" method="POST">
</FORM>
</section>
</body>
</html>