-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.php
45 lines (38 loc) · 1.04 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
<?php
include('navbar.html');
?>
<br>
<br>
<br>
</body>
<div class="col-xs4">
<?php
require('config/connection.php');
require('src/Comment.php');
session_start();
if ($_SERVER['REQUEST_METHOD'] == "POST") {
if (isset($_POST['comment'])) {
$content = $_POST['comment'];
$comment = new Comment();
$comment->setAuthorId($_SESSION['userId']);
$comment->setComment($content);
$comment->setPostId($_GET['id']);
$comment->comment($conn);
}
header('refresh: 1;');
}
if ($_SERVER['REQUEST_METHOD'] == "GET") {
$sql = "SELECT * FROM posts WHERE id= " . $_GET['id'];
$result = $conn->query($sql);
foreach ($result as $row) {
echo $row['content'] . "<br>";
}
$sql = "SELECT * FROM comments JOIN users ON comments.author_id = users.id WHERE comments.post_id=" . $_GET['id'];
$result = $conn->query($sql);
foreach ($result as $row) {
echo $row['username'] . " commented " . $row['date'] . " : ";
echo $row['comment'] . "<br>";
}
}
?>
<div class="col-xs4">