<?php
	
$help=$_REQUEST['name'];	
$name = htmlspecialchars($help); //vytahne si jmeno a obsah komentare, osetri html znaky
$help=$_REQUEST['comments'];
$comments = htmlspecialchars($help);
$help=$_REQUEST['pwd'];
$pwd= htmlspecialchars($help);
$g=0;




require("db/db.php"); //spoji se s php souborem, ktery zajistuje pripojeni k databazi

	$result = mysqli_query($con, "SELECT * FROM acc ORDER BY id_user ASC"); //získávají se informace z databáze

while($row=mysqli_fetch_array($result)){ //porovnávají se výsledky
if (($name==$row['name']) and ($pwd==$row['pass'])){ 
  $g=1;
  $id=$row['id_user'];
 }
}
if ($g==1) {

	mysqli_query($con, "INSERT INTO comments(id_user, comments) VALUES('$id','$comments')"); //vlozi do databaze data
	
$result = mysqli_query($con, "SELECT * FROM comments INNER JOIN acc ON comments.id_user = acc.id_user 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 "<p>" . $row['comments'] . "</p></br>";
echo "<h3>" . $row['date_publish'] . "</h3>";
echo "</div>";
} } else { echo "Neplatné jméno nebo heslo";} 
mysqli_close($con); //ukonci spojeni s databazi
?>