Y
Y
Yevhenii K2015-10-22 14:52:48
PHP
Yevhenii K, 2015-10-22 14:52:48

How to make php create a new block in html?

Good afternoon! Help a newbie, I'm writing a script to display comments. At the moment, it writes the comment to the database, and displays it under the input box, but with the new one, the old one is deleted. How to make php create a new block in html with the text of the comment with each new comment and save the previous ones?
Thank you.
Input form

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8">
</head>
<body>
  <div class="full_comments">
    <form action="index_com.php" method="POST">
      <textarea name="coment" id="body" cols="20" rows="5"></textarea>
      <input type="submit" value="Отправить">
    </form>
  </div>
</body>
</html>

Processing script
include("connect_db.php");

if (($_POST['coment']) != '') {
  $coment = $_POST['coment'];
  $add_com_db = "INSERT INTO `coments` VALUES ('','$coment')";
  $update = $connect->exec($add_com_db);
  include("output_com.html"); // Форма вывода
} else {
  echo 'Need coment';
}

Output form
<div class="suda">
  <div class="com">
    <?php
    echo $coment;
    ?>
  </div>
</div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Izmailov, 2015-10-22
@WapGeaR

Seems like you figured out what you need.
There is no way without javascript.
2 options:
1. Send a message with Ajax, check if everything is fine on a new one, again load all comments via ajax and rewrite the block with new comments.
2. When sending a new comment, add a block (innerHTML) with the comment text and the author.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question