-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_post.php
More file actions
53 lines (48 loc) · 1.35 KB
/
Copy pathadd_post.php
File metadata and controls
53 lines (48 loc) · 1.35 KB
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
44
45
46
47
48
49
50
51
52
53
<?php
include 'application/bdd_connection.php';
if(empty($_POST))
{
// Récupération de tous les auteurs du blog.
$query =
'
SELECT
Id,
FirstName,
LastName
FROM
Author
';
$resultSet = $pdo->query($query);
$authors = $resultSet->fetchAll();
// Récupération de toutes les catégories du blog.
$query =
'
SELECT
Id,
Name
FROM
Category
';
$resultSet = $pdo->query($query);
$categories = $resultSet->fetchAll();
// Sélection et affichage du template PHTML.
$template = 'add_post';
include 'layout.phtml';
}
else
{
// Ajout d'un article du blog.
$query =
'
INSERT INTO
Post
(Title, Contents, Author_Id, Category_Id, CreationTimestamp)
VALUES
(?, ?, ?, ?, NOW())
';
$resultSet = $pdo->prepare($query);
$resultSet->execute([$_POST['title'], $_POST['contents'], $_POST['author'], $_POST['category']]);
// Retour à la page d'accueil une fois que le nouvel article du blog a été ajouté.
header('Location: index.php');
exit();
}