-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanage.php
More file actions
37 lines (24 loc) · 978 Bytes
/
Copy pathmanage.php
File metadata and controls
37 lines (24 loc) · 978 Bytes
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
<?php
require 'News.php';
try{
// connect to database
//TODO: check for connect with text file
$db = new PDO('mysql:host=localhost;dbname=news_form','root','');
}catch(Exception $e){
die($e->getMessage());
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$header = isset($_POST['header']) ? htmlentities($_POST['header']) : '';
$newsDate = isset($_POST['newsDate']) ? htmlentities($_POST['newsDate']) : '';
$author = isset($_POST['author']) ? htmlentities($_POST['author']) : '';
$text = isset($_POST['text']) ? htmlentities($_POST['text']) : '';
$date = new DateTime($newsDate);
$q = $db->prepare('INSERT INTO News SET header = :header, newsDate = :newsDate, author = :author, text = :text');
$q->bindValue(':header', $header);
$q->bindValue(':newsDate', $date->format('Y-m-d'));
$q->bindValue(':author', $author);
$q->bindValue(':text', $text);
$q->execute();
// redirect to the list of news
header('Location: list.phtml');
}