Repository navigation
Expand file tree
/
Copy pathcomments.php
More file actions
155 lines (118 loc) · 4.92 KB
/
Copy pathcomments.php
File metadata and controls
155 lines (118 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
include 'components/connect.php';
if(isset($_COOKIE['user_id'])){
$user_id = $_COOKIE['user_id'];
}else{
$user_id = '';
header('location:home.php');
}
if(isset($_POST['delete_comment'])){
$delete_id = $_POST['comment_id'];
$delete_id = filter_var($delete_id, FILTER_SANITIZE_STRING);
$verify_comment = $conn->prepare("SELECT * FROM `comments` WHERE id = ?");
$verify_comment->execute([$delete_id]);
if($verify_comment->rowCount() > 0){
$delete_comment = $conn->prepare("DELETE FROM `comments` WHERE id = ?");
$delete_comment->execute([$delete_id]);
$message[] = 'comment deleted successfully!';
}else{
$message[] = 'comment already deleted!';
}
}
if(isset($_POST['update_now'])){
$update_id = $_POST['update_id'];
$update_id = filter_var($update_id, FILTER_SANITIZE_STRING);
$update_box = $_POST['update_box'];
$update_box = filter_var($update_box, FILTER_SANITIZE_STRING);
$verify_comment = $conn->prepare("SELECT * FROM `comments` WHERE id = ? AND comment = ? ORDER BY date DESC");
$verify_comment->execute([$update_id, $update_box]);
if($verify_comment->rowCount() > 0){
$message[] = 'comment already added!';
}else{
$update_comment = $conn->prepare("UPDATE `comments` SET comment = ? WHERE id = ?");
$update_comment->execute([$update_box, $update_id]);
$message[] = 'comment edited successfully!';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>user comments</title>
<!-- font awesome cdn link -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css">
<!-- custom css file link -->
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<?php include 'components/user_header.php'; ?>
<?php
if(isset($_POST['edit_comment'])){
$edit_id = $_POST['comment_id'];
$edit_id = filter_var($edit_id, FILTER_SANITIZE_STRING);
$verify_comment = $conn->prepare("SELECT * FROM `comments` WHERE id = ? LIMIT 1");
$verify_comment->execute([$edit_id]);
if($verify_comment->rowCount() > 0){
$fetch_edit_comment = $verify_comment->fetch(PDO::FETCH_ASSOC);
?>
<section class="edit-comment">
<h1 class="heading">edti comment</h1>
<form action="" method="post">
<input type="hidden" name="update_id" value="<?= $fetch_edit_comment['id']; ?>">
<textarea name="update_box" class="box" maxlength="1000" required placeholder="please enter your comment" cols="30" rows="10"><?= $fetch_edit_comment['comment']; ?></textarea>
<div class="flex">
<a href="comments.php" class="inline-option-btn">cancel edit</a>
<input type="submit" value="update now" name="update_now" class="inline-btn">
</div>
</form>
</section>
<?php
}else{
$message[] = 'comment was not found!';
}
}
?>
<section class="comments">
<h1 class="heading">your comments</h1>
<div class="show-comments">
<?php
$select_comments = $conn->prepare("SELECT * FROM `comments` WHERE user_id = ?");
$select_comments->execute([$user_id]);
if($select_comments->rowCount() > 0){
while($fetch_comment = $select_comments->fetch(PDO::FETCH_ASSOC)){
$select_content = $conn->prepare("SELECT * FROM `content` WHERE id = ?");
$select_content->execute([$fetch_comment['content_id']]);
$fetch_content = $select_content->fetch(PDO::FETCH_ASSOC);
?>
<div class="box" style="<?php if($fetch_comment['user_id'] == $user_id){echo 'order:-1;';} ?>">
<div class="content"><span><?= $fetch_comment['date']; ?></span><p> - <?= $fetch_content['title']; ?> - </p><a href="watch_video.php?get_id=<?= $fetch_content['id']; ?>">view content</a></div>
<p class="text"><?= $fetch_comment['comment']; ?></p>
<?php
if($fetch_comment['user_id'] == $user_id){
?>
<form action="" method="post" class="flex-btn">
<input type="hidden" name="comment_id" value="<?= $fetch_comment['id']; ?>">
<button type="submit" name="edit_comment" class="inline-option-btn">edit comment</button>
<button type="submit" name="delete_comment" class="inline-delete-btn" onclick="return confirm('delete this comment?');">delete comment</button>
</form>
<?php
}
?>
</div>
<?php
}
}else{
echo '<p class="empty">no comments added yet!</p>';
}
?>
</div>
</section>
<!-- comments section ends -->
<?php include 'components/footer.php'; ?>
<!-- custom js file link -->
<script src="js/script.js"></script>
</body>
</html>