-
Notifications
You must be signed in to change notification settings - Fork 1
/
comment.php
43 lines (37 loc) · 1.32 KB
/
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
43
<?php
require_once 'helpers.php';
require_once 'functions.php';
require_once 'data.php';
require_once 'session.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$required = ['text', 'post_id'];
$rules = [
'text' => function ($value) {
return validate_comment($value, COMMENT_MIN_LENGTH);
},
'post_id' => function ($value) use ($connection) {
return validate_post_id($connection, $value);
}
];
$comment = filter_input_array(INPUT_POST, [
'text' => FILTER_DEFAULT,
'post_id' => FILTER_VALIDATE_INT
], true);
$validation_errors = full_form_validation($comment, $rules, $required);
if (!$validation_errors) {
$sql = 'INSERT INTO comments (content, user_id, post_id)' .
' VALUES (?, ?, ?)';
$stmt = db_get_prepare_stmt($connection, $sql, [$comment['text'], $user['user_id'], $comment['post_id']]);
mysqli_stmt_execute($stmt);
header('Location: users_profile.php?id=' . $this_user['id']);
exit;
}
$page_content = include_template('post_templates/post-window.php', [
'post' => $post,
'user_info' => $user_info,
'this_user' => $this_user,
'is_subscribe' => $is_subscribe,
'user' => $user,
'validation_errors' => $validation_errors
]);
}