-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadmore.php
149 lines (127 loc) · 3.63 KB
/
readmore.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
require_once "./database.php";
$post_id = $_GET['id'];
$sql = "SELECT * FROM post WHERE id=$post_id";
$result = mysqli_query($connection, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$data[] = $row;
}
$data = array_shift($data);
}
if (isset($_POST['submit_comment'])) {
$commentor = $_POST['commentor'];
$comment = $_POST['comments'];
$postID = $data['id'];
$mysql = "INSERT INTO comment(name,comment,post_id) VALUES('$commentor','$comment','$postID')";
if (!mysqli_query($connection, $mysql)) {
die();
}
}
$comkey = $data['id'];
$commentsql = "SELECT * FROM comment WHERE post_id=$comkey";
$comres = mysqli_query($connection, $commentsql);
if (mysqli_num_rows($comres) > 0) {
while ($row = mysqli_fetch_assoc($comres)) {
$along[] = $row;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php
require_once('./common/common-header.php');
?>
<style>
.error {
color: red;
}
</style>
</head>
<body>
<!-- Navigation -->
<?php
require_once('./common/header.php');
?>
<!-- Page Content -->
<div class="container">
<div class="row">
<!-- Post Content Column -->
<div class="col-lg-8">
<!-- Title -->
<h1 class="mt-4">Full Post</h1>
<div class="posts">
<hr>
<!-- Date/Time -->
<p><?php echo $data['created_at']; ?></p>
<hr>
<!-- Preview Image -->
<img class="img-fluid rounded" src="<?php echo "./Admin/images/" . $data['image']; ?>" alt="">
<hr>
<!-- Post Content -->
<p> <?php echo $data['content']; ?></p>
</div>
<div class="card my-4">
<h5 class="card-header">Leave a Comment:</h5>
<div class="card-body">
<form id="commentForm" action="readmore.php?id=<?php echo $post_id; ?>" method="POST">
<div class="form-group">
<input type="text" name="commentor" placeholder="Your Name" id="commentor-name" class="form-control">
<label class="error" style="color: red"></label>
</div>
<div class="form-group">
<textarea name="comments" id="comments" placeholder="Add your comment" class="form-control" rows="3"></textarea>
<label class="error" style="color: red"></label>
</div>
<button type="submit" name="submit_comment" id="submit_comment" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
<?php
if (!empty($along)) {
foreach ($along as $val) {
?>
<div class="media mb-4 border">
<img class="d-flex mr-3 rounded-circle" src="http://placehold.it/50x50" alt="">
<div class="media-body">
<h5 class="mt-0"><?php echo $val['name']; ?></h5>
<?php echo $val['comment'] ?>
<hr>
</div>
</div>
<?php }
} else {
echo "No comment Found";
} ?>
</div>
<!-- Sidebar Widgets Column -->
<?php
require_once('./common/sidebar.php');
?>
</div>
<!-- /.row -->
</div>
<!-- /.container -->
<!-- Footer -->
<?php
require_once('common/footer.php');
?>
<?php
require_once('./common/common-footer.php');
?>
<script>
$(function() {
$("#commentForm").validate({
rules: {
comments: 'required',
commentor: 'required',
},
message: {
comments: "This field is required",
commentor: "This field is reqruired",
}
})
})
</script>
</body>