Show sourcecode
The following files exists in this folder. Click to view.
webbsrvprg/projekt/slutprojekt/
board_random.php
board_travel.php
board_vgy.php
create_comment.php
create_post.php
create_tables.php
darkmode.js
fetch_comments.php
fetch_posts.php
fetch_posts_random.php
forgot_password.php
index.php
login.php
nav.css
nav.php
post.php
register.php
reset_password.php
sql_inject.php
verify.php
fetch_comments.php
30 lines ASCII Windows (CRLF)
<?php
session_start();
include ('../../incl/dbconnect.php');
if(!isset($_GET['post_id'])){
echo json_encode([]);
exit;
}
$post_id = intval($_GET['post_id']);
$stmt = $dbconn->prepare("
SELECT
c.comment_id,
c.content,
c.created_at,
u.username,
(SELECT COUNT(*) FROM Posts_slutprojekt WHERE user_id = c.user_id) AS post_count
FROM Comments_slutprojekt c
JOIN Users_slutprojekt u ON c.user_id = u.user_id
WHERE c.post_id = :post_id
ORDER BY c.created_at ASC
");
$stmt->execute([':post_id' => $post_id]);
$comments = $stmt->fetchAll(PDO::FETCH_ASSOC);
header('Content-Type: application/json');
echo json_encode($comments);
?>