Guest User

Untitled

a guest
Nov 21st, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. <div class=”comment”>
  2. <p>Автор:</p>
  3. <p>Комментарий:</p>
  4. <p>Время комментария</p>
  5. <div>
  6.  
  7. <?php
  8. function checkData()
  9. {
  10. if (!empty ($_GET ['userName']) and !empty($_GET['content'])) {
  11.  
  12. return true;
  13. }
  14.  
  15. return false;
  16. }
  17.  
  18. function saveComment($author, $content)
  19. {
  20. $res = file_put_contents('test2.php', $author . ':' . $content . ':' . time() . ':', FILE_APPEND);
  21. if ($res === false) {
  22. echo 'Запись не удалась...';
  23. } else {
  24. header('Location: test2.php?msg=success');
  25. }
  26. }
  27.  
  28. if (!empty($_GET['formName']) and $_GET['formName'] == 'commentForm') {
  29. if (checkData()) {
  30. saveComment($_GET['userName'], $_GET['content']);
  31. } else exit('Все поля обязательны для заполнения');
  32. }
  33. ?>
  34.  
  35. <?php if ($_GET['msg'] == 'success'): ?>
  36. <p>Комментарий успешно добавлен</p>
  37. <?php endif; ?>
  38.  
  39. <form>
  40. <input type="text" name="userName"><br>
  41. <textarea name="content"></textarea><br>
  42. <input type="hidden" name="formName" value="commentForm">
  43. <button>Submit</button>
  44. </form>
Add Comment
Please, Sign In to add comment