Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function addComment($conn){
- if(isset($_POST['commentSubmit'])){
- $uid = $_SESSION['id'];
- $nameAuthor = $_SESSION['firstname'];
- $date = $_POST['date'];
- $text = $_POST['text'];
- $sql = "INSERT INTO comment (uid, nameAuthor, date, text) VALUES ('$uid', '$nameAuthor', '$date', '$text')";
- $result = $conn->query($sql);
- }
- }
- function getComments($conn){
- $sql = "SELECT * FROM comment ORDER BY id DESC";
- $result = $conn->query($sql);
- while ($row = $result->fetch_assoc()) {
- $id = $row['uid'];
- $sql2 = "SELECT * FROM user WHERE id='$id'";
- $result2 = $conn->query($sql2);
- if ($row2 = $result2->fetch_assoc()) {
- $id1 = $_SESSION['id'];
- echo '<div class="panel">
- <div class="infopanel">
- <div class="row">
- <div class="col-xs-3">
- <img src="graham.jpg" width="100%">
- </div>
- <div class="col-xs-9">
- <div style="margin-bottom: 10px;">
- <div class="name">'.$row2['firstname'].'</div>
- <div class="data" style="float: right;">'.$row['date'].'</div>
- </div>
- <div class="comment">
- '.($row['text']).'
- </div>
- </div>
- </div>';
- if(isset($_SESSION['id'])){
- if ($_SESSION['id'] == $row2['id']) {
- echo'
- <div class="divlikebuttons">
- <div class="likebuttons">
- <a href="" class="likebutton">
- <form class="edit-form" method="POST" action="editcomment.php">
- <input type="hidden" name="id" value="'.$row['id'].'">
- <input type="hidden" name="uid" value="'.$row['uid'].'">
- <input type="hidden" name="nameAuthor" value="'.$row['nameAuthor'].'">
- <input type="hidden" name="date" value="'.$row['date'].'">
- <input type="hidden" name="text" value="'.$row['text'].'">
- <button><span class="glyphicon glyphicon-edit" aria-hidden="true"></span> Изменить</button>
- </form>
- </a>
- <a href="" class="likebutton">
- <form class="delete-form" method="POST" action="'.deleteComment($conn, $id1).'">
- <input type="hidden" name="nameAuthor" value="'.$row['nameAuthor'].'">
- <input type="hidden" name="date" value="'.$row2['date'].'">
- <button type="submit" name="commentDelete"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Удалить</button>
- </form>
- </a>
- ';
- } else {
- echo '
- <div class="divlikebuttons">
- <div class="likebuttons">
- <a href="" class="likebutton"><span class="glyphicon glyphicon-comment" aria-hidden="true"></span> Ответить</a>
- <a href="" class="likebutton"><span class="glyphicon glyphicon-comment" aria-hidden="true"></span> С цитатой</a>
- <a href="" class="likebutton"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> В цитатник</a>
- <a href="" class="likebutton"><span class="glyphicon glyphicon-share-alt" aria-hidden="true"></span> Обратиться</a>
- ';
- }
- echo '</div> </div>';
- } else {
- echo '<div class="divlikebuttons">
- <div class="likebuttons">
- <a href="index.php" class="likebutton"><span class="glyphicon glyphicon-comment" aria-hidden="true"></span> Ответить</a>
- <a href="index.php" class="likebutton"><span class="glyphicon glyphicon-comment" aria-hidden="true"></span> С цитатой</a>
- <a href="index.php" class="likebutton"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> В цитатник</a>
- <a href="index.php" class="likebutton"><span class="glyphicon glyphicon-share-alt" aria-hidden="true"></span> Обратиться</a>
- </div>
- </div>
- ';
- }
- echo '
- </div>
- </div>';
- }
- }
- }
- function editComment($conn){
- if(isset($_POST['commentSubmit'])){
- $id = $_POST['id'];
- $uid = $_SESSION['id'];
- $nameAuthor = $_SESSION['firstname'];
- $date = $_POST['date'];
- $text = $_POST['text'];
- $sql = "UPDATE comment SET text='$text' WHERE id='$id'";
- $result = $conn->query($sql);
- header("Location: site.php");
- }
- }
- function deleteComment($conn, $id1) {
- if(isset($_POST['commentDelete'])){
- $nameAuthor = $_POST['nameAuthor'];
- $date = $_POST['date'];
- $sql = "DELETE FROM comment WHERE nameAuthor='$nameAuthor' AND date='$date' AND uid='$id1'";
- $result = $conn->query($sql);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement