-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.php
84 lines (84 loc) · 2.51 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
<?php
include("header.php");
if(isset($_GET['postID'])){
$postID=$_GET['postID'];
}
else{
header("Location: home.php");
}
$sql="select * from post where postID=$postID";
$res=$conn->query($sql);
if($res->num_rows!=0){
$row=$res->fetch_assoc();
$creator=$row['creator'];
$title=$row['title'];
$body=$row['body'];
$upvotes=$row['upvotes'];
$downVotes=$row['downVotes'];
$vote=$upvotes-$downVotes;
$attachment=$row['attachment'];
$originAt=$row['originAt'];
}
else{
header("Location: home.php");
}
?>
<div class="containerPost">
<div class="title-bar">
<?php echo $title;?>
</div>
<div class="timestamp">
Author : <?php echo $creator;?>
</div><br>
<div class="timestamp">
created : <?php echo $originAt;?>
</div>
<p><?php echo $body;?></p>
<img src="<?php echo $attachment;?>">
<button id="csec" onclick="revealHideComments()">Comment Section</button>
<form id="commentForm" action="<?php echo "post.php?postID=$postID";?>" method="post">
<input type="text" name="comment" placeholder="comment">
<button type="submit" name="submitComment" value="submitComment">Comment</button>
</form>
<?php
$sql3="select * from comments where postID='$postID' order by originAt desc";
$res3=$conn->query($sql3);
for($i=0;$i<$res3->num_rows;$i++){
$row3=$res3->fetch_assoc();
$commentBy=$row3['commentBy'];
$commentBody=$row3['body'];
$commentOrigin=$row3['originAt'];
$sql4="select * from profileData where username='$commentBy'";
$res4=$conn->query($sql4);
$row4=$res4->fetch_assoc();
$profilePic=$row4['profilePic'];
?>
<div id="toHide" name="toHide">
<span id="authorArea">
<img src="<?php echo $profilePic;?>">
<a href="profile.php?username=<?php echo $commentBy;?>"><?php echo $commentBy;?></a>
</span>
<p id="commentBody">
<?php echo $commentBody;?>
</p>
<p id="commentTimeStamp">
<?php echo $commentOrigin;?>
</p>
</div>
<?php
}
?>
</div>
<script src="postControl.js?ver=<?php echo rand(100,999);?>"></script>
<?php
include("footer.php");
?>
<?php
if(isset($_POST['submitComment'])){
$bodyC=$_POST['comment'];
$sql1="insert into comments(commentBy,postID,body) values('$username','$postID','$bodyC')";
if($conn->query($sql1)){
header("Location: post.php?postID=$postID");
}
}
?>