-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.php
136 lines (112 loc) · 4.88 KB
/
post.php
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
<?php
include "include/header.php";
?>
<?php include 'include/navigation.php' ?>
<!-- Navigation -->
<?php
if(isset($_GET['post_id']))
{
$post_id = $_GET['post_id'];
$post_id = mysqli_real_escape_string($connect,$post_id);
$query = "SELECT * FROM posts WHERE post_id ='$post_id'";
$result = mysqli_query($connect,$query);
$row = mysqli_fetch_assoc($result);
}
else
{
header('Location:index.php');
}
?>
<!-- Page Content -->
<div class="container">
<div class="row">
<!-- Blog Post Content Column -->
<div class="col-lg-8">
<!-- Blog Post -->
<!-- Title -->
<h1><?php echo $row['post_title'] ?></h1>
<!-- Author -->
<p class="lead">
by <a href="#"><?php echo $row['post_author'] ?></a>
</p>
<hr>
<!-- Date/Time -->
<p><span class="glyphicon glyphicon-time"></span> <?php echo $row['post_date'] ?> at 9:00 PM</p>
<hr>
<!-- Preview Image -->
<img class="img-responsive" src="images/<?php echo $row['post_image'] ?>" alt="">
<hr>
<!-- Post Content -->
<p class="lead"><?php echo $row['post_content'] ?></p>
<hr>
<?php
if (isset($_POST['comment']))
{
$post_id = $_POST['post_id'];
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['content'];
if(!empty($name) && !empty($email) && !empty($comment))
{
$comment = mysqli_real_escape_string($connect,$comment);
$query = "INSERT INTO comments (comment_post_id,comment_author,comment_email,comment_content,comment_date) ";
$query .= "VALUES ('$post_id','$name','$email','$comment',now()) ";
$result = mysqli_query($connect,$query);
}
else
{
echo "<script> alert('Comment field can not be empty '); </script>";
}
}
?>
<!-- Blog Comments -->
<!-- Comments Form -->
<div class="well">
<h4>Leave a Comment:</h4>
<form role="form" action="" method="POST">
<div class="form-group">
<input class="form-control" type="text" name="name" placeholder="Your Name">
</div>
<div class="form-group">
<input class="form-control" type="email" name="email" placeholder="Your Email">
</div>
<div class="form-group">
<textarea name="content" class="form-control" rows="3"></textarea>
</div>
<div class="form-group">
<input type="hidden" value="<?php echo $row['post_id'] ?>" name="post_id">
</div>
<button type="submit" class="btn btn-primary" name="comment">Submit</button>
</form>
</div>
<hr>
<h5>Total Comment : <?php echo $row['post_comment_counts'] ?></h5>
<!-- Posted Comments -->
<?php
$query = "SELECT * FROM comments WHERE comment_status = 'approved' AND comment_post_id = '$post_id'";
$result = mysqli_query($connect,$query);
while ($rows= mysqli_fetch_assoc($result))
{
?>
<!-- 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 $rows['comment_author'] ?>
<small><?php echo $rows['comment_date'] ?></small>
</h4>
<?php echo $rows['comment_content'] ?>
</div>
</div>
<?php }?>
<!-- Comment -->
</div>
<!-- Blog Sidebar Widgets Column -->
<?php include "include/sidebar.php" ?>
</div>
<!-- /.row -->
<hr>
<!-- Footer -->
<?php include "include/footer.php" ?>