-
Notifications
You must be signed in to change notification settings - Fork 2
/
thread.php
144 lines (115 loc) · 5.52 KB
/
thread.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
<?php include 'starter.html'; ?>
<?php
include 'dbconnect.php';
include 'header.php'; ?>
<?php
$id=$_GET['threadid'];
$sql="SELECT * FROM `thread` WHERE thread_id=$id";
$result=mysqli_query($conn,$sql);
while($row=mysqli_fetch_assoc($result)){
$title=$row['thread_title'];
$desc=$row['thread_desc'];
$thread_user_id=$row['thread_user_id'];
//query for name of the posted by
$sql2="SELECT user_email FROM `users` WHERE user_id='$thread_user_id'";
$result2=mysqli_query($conn,$sql2);
$row2=mysqli_fetch_assoc($result2);
$posted_by=$row2['user_email'];
}
?>
<?php
$showalert=false;
$method=$_SERVER['REQUEST_METHOD'];
if($method=='POST'){
//insert into comment into db
$comment=$_POST['comment'];
$comment=str_replace("<","<","$comment");
$comment=str_replace(">",">","$comment");
$sno=$_POST['sno'];
$sql="INSERT INTO `comments`( `comment_content`, `thread_id`, `comment_by`, `comment_time`) VALUES ('$comment','$id','$sno',current_timestamp())";
$result=mysqli_query($conn,$sql);
$showalert=true;
if($showalert){
echo '<div class="alert alert-success alert-dismissible fade show " role="alert">
<strong>Success! </strong>Your comment has been added succesfully.
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>';
}
}
?>
<div class="container my-2">
<div class="jumbotron ">
<h1 class="display-4"> <?php echo $title; ?> </h1>
<p class="lead"> <?php echo $desc; ?></p>
<hr class="my-4">
<p>This is peer to peer forum for sharing knowledge with eacch other. No Spam / Advertising.
Do not post copyright-infringing material. ...
Do not post “offensive” posts, links or images. ...
Do not cross post questions. ...
Remain respectful of other members at all times. </p>
<p class="p-1">Posted By- <strong class="p-1"><?php echo $posted_by ?></strong>
<p>
</div>
</div>
<?php
if(isset ($_SESSION['loggedin']) && $_SESSION['loggedin']==true){
echo'
<div class="container " style="min-height:200px;">
<h1 class="font-italic ">Post a Comment</h1>
<form action="'. $_SERVER['REQUEST_URI'] .'" method="post">
<div class="form-group">
<label for="exampleFormControlTextarea1">Type your comment</label>
<textarea class="form-control" id="comment" name="comment" rows="3"></textarea>
<input type="hidden" name="sno" value="'.$_SESSION["sno"].'">
</div>
<button type="submit" class="btn btn-primary">Post comment</button>
</form>
</div>
';
}
else{
echo ' <div class="container">
<h1 class="font-italic py-2">Post a Comment</h1>
<div class="alert alert-warning" role="alert">
You are not logged in ,Please login to able post a comments.
</div>
</div>';
}
?>
<div class="container my-2">
<h1 class="font-italic ">Discussion</h1>
<?php
$noresult=true;
$id=$_GET['threadid'];
$sql="SELECT * FROM `comments` WHERE thread_id=$id";
$result=mysqli_query($conn,$sql);
while($row=mysqli_fetch_assoc($result)){
$noresult=false;
$id=$row['comment_id'];
$content=$row['comment_content'];
$comment_time=$row['comment_time'];
$thred_user_id=$row['comment_by'];
$sql2="SELECT user_email FROM `users` WHERE user_id='$thred_user_id'";
$result2=mysqli_query($conn,$sql2);
$row2=mysqli_fetch_assoc($result2);
echo ' <div class="media my-2 border">
<img src="image/user.jpg" width="80px" class="mr-3" alt="...">
<div class="media-body">
<p class="font-weight-bold my-0">'.$row2['user_email'].' at '.$comment_time.'</p>
'.$content.'
</div>
</div>';
}
if($noresult){
echo '<div class="jumbotron jumbotron-fluid ">
<div class="container">
<h1 class="display-4">No Result for this question</h1>
<p class="lead ">Be the first person to give answer this question.To give answer this question you have to login first.</p>
</div>
</div>';
}
?>
</div>
<?php include 'footer.php'; ?>