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
create_comment.php
28 lines UTF-8 Windows (CRLF)
<?php
session_start();
include ('../../incl/dbconnect.php');
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(!isset($_SESSION['user_id'])){
echo "Du måste vara inloggad för att kommentera.";
exit;
}
$user_id = $_SESSION['user_id'];
$post_id = intval($_POST['post_id']);
$comment_content = trim($_POST['comment_content']);
if(empty($comment_content)){
echo "Kommentaren får inte vara tom.";
exit;
}
$stmt = $dbconn->prepare("INSERT INTO Comments_slutprojekt (post_id, user_id, content, created_at) VALUES (:post_id, :user_id, :content, NOW())");
$stmt->execute([
':post_id' => $post_id,
':user_id' => $user_id,
':content' => $comment_content
]);
echo "Kommentar skapad.";
}
?>