<?php

if(isset($_POST['postcomment'])) {
$xml = simplexml_load_file("db/".$currentpage."-comment.xml");
$xml_comment = $xml->addChild("comment");
$xml_comment->addChild("username", $_SESSION["username"]);
$xml_comment->addChild("rating", $_POST["rating"]);
$xml_comment->addChild("commenttext", $_POST["comment"]);
$xml->saveXML("db/".$currentpage."-comment.xml");
}
?>

<div class="comments">
    
    <?php
$xml = simplexml_load_file("db/".$currentpage."-comment.xml");
if ($xml->comment !== '')
foreach ($xml->comment as $comment) {
    printf(
        "<div class='showcomments'>
        <p>Username: %s | Rating: %s</p>
        <p> %s</p></div>",
        $comment->username,
        $comment->rating,
        $comment->commenttext
    );
}?>
<form action="" method="post">
  Write your own:<br>

    <input type="radio" name="rating" value="1">1
    <input type="radio" name="rating" value="2">2
    <input type="radio" name="rating" value="3">3
    <input type="radio" name="rating" value="4">4
    <input type="radio" name="rating" value="5">5
    <br>
    <textarea type="text" name="comment" id="textcomment"></textarea><br>
 <input type="submit" name="postcomment">
</form>
</div>