Repository navigation
Expand file tree
/
Copy pathcomments.php
More file actions
79 lines (64 loc) · 2.78 KB
/
Copy pathcomments.php
File metadata and controls
79 lines (64 loc) · 2.78 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
<?php
if( isset( $_POST['create_comment'] ) ) {
$comment_post_id = $_GET['p_id'];
$comment_author = $_POST['comment_author'];
$comment_email = $_POST['comment_email'];
$comment_content = $_POST['comment_content'];
$query = "INSERT INTO comments (comment_post_id, comment_author, comment_email, comment_content, comment_status, comment_date) VALUES ($comment_post_id, '$comment_author', '$comment_email', '$comment_content', 'unapproved', now())";
$create_comment_query = mysqli_query($connection, $query);
$query = "UPDATE posts SET post_comment_count = post_comment_count+1 WHERE post_id = $comment_post_id";
$increment_comment_query = mysqli_query($connection, $query);
confirmQuery($increment_comment_query);
confirmQuery($create_comment_query);
header("Location: post.php?p_id=$comment_post_id");
}
?>
<!-- Blog Comments -->
<!-- Comments Form -->
<div class="well">
<h4>Leave a Comment:</h4>
<form role="form" action="" method="post">
<div class="form-group">
<label for="author">Author</label>
<input type="text" class="form-control" id="author" name="comment_author">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="text" class="form-control" id="email" name="comment_email">
</div>
<div class="form-group">
<label for="comment">Your Comment</label>
<textarea class="form-control" rows="3" id="comment" name="comment_content"></textarea>
</div>
<button type="submit" class="btn btn-primary" name="create_comment">Submit</button>
</form>
</div>
<!-- End Of Comments Form -->
<hr>
<!-- Posted Comments -->
<?php
$comment_post_id = $_GET['p_id'];
$query = "SELECT * FROM comments WHERE comment_post_id = $comment_post_id and comment_status = 'approved' ORDER BY comment_id DESC";
$select_all_comments_query = mysqli_query($connection, $query);
$count = 0;
while($row = mysqli_fetch_assoc($select_all_comments_query)) {
$comment_author = $row['comment_author'];
$comment_date = $row['comment_date'];
$comment_content = $row['comment_content'];
$count++;
?>
<!-- Comment -->
<div class="media">
<a class="pull-left" href="#"> <img class="media-object" src="http://placehold.it/64x64" alt=""> </a>
<div class="media-body">
<h4 class="media-heading"><?php echo $comment_author; ?>
<small><?php echo $comment_date; ?></small>
</h4> <?php echo $comment_content; ?>
</div>
</div>
<!-- End Of Comment Here -->
<?php
}//end of while
if($count == 0)
echo "<h3>Be The First One To Comment!</h3>";
?>