-
Notifications
You must be signed in to change notification settings - Fork 36
/
Comment.php
29 lines (24 loc) · 952 Bytes
/
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
<?php
class Comment {
public function __construct($config) {
$dbconfig = $config['database'];
$dsn = 'mysql:host=' . $dbconfig['host'] . ';dbname=' . $dbconfig['name'];
$this->db = new PDO($dsn, $dbconfig['user'], $dbconfig['pass']);
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
public function create() {
if(!isset($_SESSION['AUTHENTICATED'])) {
die('not auth');
header("Location: /");
exit;
}
$sql = 'INSERT INTO comment (created_by, created_on, story_id, comment) VALUES (?, NOW(), ?, ?)';
$stmt = $this->db->prepare($sql);
$stmt->execute(array(
$_SESSION['username'],
$_POST['story_id'],
filter_input(INPUT_POST, 'comment', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
));
header("Location: /story/?id=" . $_POST['story_id']);
}
}