Advertisement
AleYalunin

Untitled

Oct 30th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. <?php
  2. function addComment($conn){
  3. if(isset($_POST['commentSubmit'])){
  4. $uid = $_SESSION['id'];
  5. $nameAuthor = $_SESSION['firstname'];
  6. $date = $_POST['date'];
  7. $text = $_POST['text'];
  8.  
  9. $sql = "INSERT INTO comment (uid, nameAuthor, date, text) VALUES ('$uid', '$nameAuthor', '$date', '$text')";
  10. $result = $conn->query($sql);
  11. }
  12. }
  13.  
  14. function getComments($conn){
  15. $sql = "SELECT * FROM comment ORDER BY id DESC";
  16. $result = $conn->query($sql);
  17. while ($row = $result->fetch_assoc()) {
  18. $id = $row['uid'];
  19. $sql2 = "SELECT * FROM user WHERE id='$id'";
  20. $result2 = $conn->query($sql2);
  21. if ($row2 = $result2->fetch_assoc()) {
  22. $id1 = $_SESSION['id'];
  23. echo '<div class="panel">
  24. <div class="infopanel">
  25. <div class="row">
  26. <div class="col-xs-3">
  27. <img src="graham.jpg" width="100%">
  28. </div>
  29. <div class="col-xs-9">
  30. <div style="margin-bottom: 10px;">
  31. <div class="name">'.$row2['firstname'].'</div>
  32. <div class="data" style="float: right;">'.$row['date'].'</div>
  33. </div>
  34. <div class="comment">
  35. '.($row['text']).'
  36. </div>
  37. </div>
  38. </div>';
  39. if(isset($_SESSION['id'])){
  40. if ($_SESSION['id'] == $row2['id']) {
  41. echo'
  42. <div class="divlikebuttons">
  43. <div class="likebuttons">
  44. <a href="" class="likebutton">
  45.  
  46. <form class="edit-form" method="POST" action="editcomment.php">
  47. <input type="hidden" name="id" value="'.$row['id'].'">
  48. <input type="hidden" name="uid" value="'.$row['uid'].'">
  49. <input type="hidden" name="nameAuthor" value="'.$row['nameAuthor'].'">
  50. <input type="hidden" name="date" value="'.$row['date'].'">
  51. <input type="hidden" name="text" value="'.$row['text'].'">
  52. <button><span class="glyphicon glyphicon-edit" aria-hidden="true"></span> Изменить</button>
  53. </form>
  54.  
  55. </a>
  56. <a href="" class="likebutton">
  57.  
  58. <form class="delete-form" method="POST" action="'.deleteComment($conn, $id1).'">
  59. <input type="hidden" name="nameAuthor" value="'.$row['nameAuthor'].'">
  60. <input type="hidden" name="date" value="'.$row2['date'].'">
  61. <button type="submit" name="commentDelete"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Удалить</button>
  62. </form>
  63.  
  64. </a>
  65. ';
  66. } else {
  67. echo '
  68. <div class="divlikebuttons">
  69. <div class="likebuttons">
  70. <a href="" class="likebutton"><span class="glyphicon glyphicon-comment" aria-hidden="true"></span> Ответить</a>
  71. <a href="" class="likebutton"><span class="glyphicon glyphicon-comment" aria-hidden="true"></span> С цитатой</a>
  72. <a href="" class="likebutton"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> В цитатник</a>
  73. <a href="" class="likebutton"><span class="glyphicon glyphicon-share-alt" aria-hidden="true"></span> Обратиться</a>
  74. ';
  75. }
  76. echo '</div> </div>';
  77. } else {
  78. echo '<div class="divlikebuttons">
  79. <div class="likebuttons">
  80. <a href="index.php" class="likebutton"><span class="glyphicon glyphicon-comment" aria-hidden="true"></span> Ответить</a>
  81. <a href="index.php" class="likebutton"><span class="glyphicon glyphicon-comment" aria-hidden="true"></span> С цитатой</a>
  82. <a href="index.php" class="likebutton"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> В цитатник</a>
  83. <a href="index.php" class="likebutton"><span class="glyphicon glyphicon-share-alt" aria-hidden="true"></span> Обратиться</a>
  84. </div>
  85. </div>
  86. ';
  87.  
  88. }
  89. echo '
  90. </div>
  91. </div>';
  92. }
  93. }
  94. }
  95.  
  96. function editComment($conn){
  97. if(isset($_POST['commentSubmit'])){
  98. $id = $_POST['id'];
  99. $uid = $_SESSION['id'];
  100. $nameAuthor = $_SESSION['firstname'];
  101. $date = $_POST['date'];
  102. $text = $_POST['text'];
  103.  
  104. $sql = "UPDATE comment SET text='$text' WHERE id='$id'";
  105. $result = $conn->query($sql);
  106. header("Location: site.php");
  107. }
  108. }
  109.  
  110. function deleteComment($conn, $id1) {
  111. if(isset($_POST['commentDelete'])){
  112.  
  113. $nameAuthor = $_POST['nameAuthor'];
  114. $date = $_POST['date'];
  115. $sql = "DELETE FROM comment WHERE nameAuthor='$nameAuthor' AND date='$date' AND uid='$id1'";
  116. $result = $conn->query($sql);
  117.  
  118. }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement