It's a simple code but i can't understand where is my mistake. I want to display succesfull message under the form when i click the submit but the message stays there all the time. When i enter in the page where the form is the message is under the form. How to take it out only when the query is succesfull ?

```
<?php
  $posted = false;
  if(isset($_POST['add']))
  {
   $posted = true;
    $email = $_POST['email'];
    $name = $_POST['name'];
    $rate = $_POST['rate'];
    $comment = $_POST['comment'];
    $dth = date("Y-m-d H:i:s");
    $q = "INSERT INTO reviews(email, name, rate, comment, date_created) VALUES ('$email', '$name', '$rate', '$comment', '$dth')";
    $k = mysqli_query($con,$q);
    }
 ?>
<body>
<h1>Leave a review</h1>
<div class="error-conteiner">

</div>
<div class="clear"></div>
<form action="" method="post" class="form-content">
    <div class="left">
        <div class="field">
            <label>E-mail <span class="required">*</span></label>
            <input type="text" value="" name="email" class="required-field" data-validate="email"/>
        </div>
        <div class="clear"></div>
        <div class="field">
            <label>Name</label>
            <input type="text" value="" name="name"/>
        </div>
        <div class="clear"></div>
        <div class="field">
            <label>Rate</label>
            <select name="rate">
                <option value=''>Choose rate</option>
                <option value='1'>1</option>
                <option value='2'>2</option>
                <option value='3'>3</option>
                <option value='4'>4</option>
                <option value='5'>5</option>
            </select>
        </div>
    </div>
    <div class="left">
        <label>Comment <span class="required">*</span></label>
        <textarea name="comment" class="comment required-field"></textarea>
    </div>
    <input type="submit" value="Send" class="btn" name="add" />

</form>
<?php
    if($posted){
    if($k)
    echo "Thank you for your comment!";

 else
    die(mysqli_error());
 }

 ?>
</body>
</html>

```