<?php
	
$name = $_REQUEST['name']; //vytahne si jmeno a obsah komentare
$comments = $_REQUEST['comments'];

if (!$name) {$name="anonym";} //pokud je jmeno nevyplnene, pak se nastavi na anonym
require("db/db.php"); //spoji se s php souborem, ktery zajistuje pripojeni k databazi

mysqli_query($con, "INSERT INTO comments(name, comments) VALUES('$name','$comments')"); //vlozi do databaze data

$result = mysqli_query($con, "SELECT * FROM comments ORDER BY id ASC"); //nacte data z databaze
while($row=mysqli_fetch_array($result)){
echo "<div class='comments_content'>";
echo "<h1>" . $row['name'] . "</h1>"; //postupne data vypisuje
echo "<h2>" . $row['date_publish'] . "</h2></br></br>";
echo "<h3>" . $row['comments'] . "</h3>";
echo "</div>";
}
mysqli_close($con); //ukonci spojeni s databazi
?>