-
Notifications
You must be signed in to change notification settings - Fork 2
/
submit_comment.php
42 lines (28 loc) · 970 Bytes
/
submit_comment.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
<?php
session_start();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_SESSION['username'])) {
$commentContent = $_POST['commentContent'];
$postID = $_POST['postID'];
include("important/db.php");
$conn = new mysqli($db_host, $db_user, $db_pass, $db_name);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$query = "INSERT INTO comments (post_id, username, comment_content) VALUES (?, ?, ?)";
$stmt = $conn->prepare($query);
$stmt->bind_param("iss", $postID, $_SESSION['username'], $commentContent);
if ($stmt->execute()) {
header("Location: view_post.php?post_id=" . $postID);
exit();
} else {
echo "Error: " . $conn->error;
}
$stmt->close();
$conn->close();
} else {
header("Location: user/login.php");
exit();
}
}
?>