This repository was archived by the owner on Jun 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost.php
More file actions
155 lines (132 loc) · 6.03 KB
/
post.php
File metadata and controls
155 lines (132 loc) · 6.03 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 'includes/header.php' ?>
<?php include 'includes/db.php' ?>
<!-- Navigation -->
<?php include 'includes/navigation.php' ?>
<?php
//add comment to database
if(isset($_POST['submit'])){
if(isset($_SESSION['user_id'])){
$com_author = $_SESSION['username'];
$com_email = $_SESSION['user_email'];
}else{
$com_author = $_POST['com_author'];
$com_email = $_POST['com_email'];
}
$com_content = $_POST['comment'];
$com_post_id = $_POST['submit'];
$post_date = date('d-m-y');
$query = "INSERT INTO comments(comment_post_id, comment_date, comment_author, comment_email, comment_content) ";
$query .= "VALUES({$com_post_id}, now(), '{$com_author}', '{$com_email}', '{$com_content}')";
mysqli_query($connection, $query);
$query = "UPDATE posts SET ";
$query.= "post_comment_count = post_comment_count + 1 ";
$query .= "WHERE post_id = {$com_post_id}";
mysqli_query($connection, $query);
header("Location:post.php?p_id={$com_post_id}");
}
?>
<!-- Page Content -->
<div class="container">
<div class="row">
<!-- Blog Post Content Column -->
<div class="col-lg-8">
<!-- Blog Post -->
<?php
if(isset($_GET['p_id'])){
$post_id = $_GET['p_id'];
}
$query = "SELECT * FROM posts WHERE post_id = $post_id";
$posts = mysqli_query($connection, $query);
while($row = mysqli_fetch_assoc($posts)){
$post_title = $row['post_title'];
$post_author = $row['post_author'];
$post_date = $row['post_date'];
$post_image = $row['post_image'];
$post_content = $row['post_content'];
?>
<!--Blog Post -->
<h2>
<a href="post.php?p_id=<?php echo $post_id; ?>"><?php echo $post_title?></a>
</h2>
<p class="lead">
by <a href="index.php"><?php echo $post_author?></a>
</p>
<p><span class="glyphicon glyphicon-time"></span> <?php echo $post_date?></p>
<hr>
<img class="img-responsive" src="images/<?php echo $post_image;?>" alt="">
<hr>
<p><?php echo $post_content?></p>
<a class="btn btn-primary" href="#">Read More <span class="glyphicon glyphicon-chevron-right"></span></a>
<hr>
<?php
}
?>
<hr>
<!-- Blog Comments -->
<!-- Comments Form -->
<div class="well">
<h4>Leave a Comment:</h4>
<form method="post" action="" enctype="multipart/form-data">
<?php
if(isset($_SESSION['user_id'])){
}else{
?>
<div class="form-group">
<lable>Name</lable>
<input type="text" name="com_author" class="form-control" placeholder="Enter your name">
</div>
<div class="form-group">
<lable>Email</lable>
<input type="email" name="com_email" class="form-control" placeholder="Enter your email">
</div>
<?php
}
?>
<div class="form-group">
<lable>Comment</lable>
<textarea name="comment" class="form-control" placeholder="Enter comment here" cols="30" rows="5"></textarea>
</div>
<button type="submit" class="btn btn-primary" name="submit" value="<?php echo $post_id; ?>">Submit Comment</button>
</form>
</div>
<hr>
<!-- Posted Comments -->
<?php
if(isset($_GET['p_id'])){
$com_post_id = $_GET['p_id'];
$query = "SELECT * FROM comments WHERE comment_post_id = {$com_post_id} ";
$view_com_query = mysqli_query($connection, $query);
while($row = mysqli_fetch_assoc($view_com_query)){
$com_author = $row['comment_author'];
$com_content = $row['comment_content'];
$com_status = $row['comment_status'];
$com_date = $row['comment_date'];
if($com_status == 2){
?>
<!-- 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 $com_author; ?>
<small><?php echo $com_date; ?></small>
</h4>
<?php echo $com_content; ?>
</div>
</div>
<?php
}
}
if(empty($com_author)){
echo "<h4 class='media-hedding'>Be the first to comment!</h4>";
}
}
?>
</div>
<!-- Blog Sidebar Widgets Column -->
<?php include 'includes/sidebar.php' ?>
<!-- /.row -->
<hr>
<!-- Footer -->
<?php include 'includes/footer.php' ?>