-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit_post.php
More file actions
53 lines (48 loc) · 1.25 KB
/
Copy pathedit_post.php
File metadata and controls
53 lines (48 loc) · 1.25 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))
{
// Validation de la query string dans l'URL.
if(!array_key_exists('id', $_GET) OR !ctype_digit($_GET['id']))
{
header('Location: index.php');
exit();
}
// Récupération d'un article du blog.
$query =
'
SELECT
Id,
Title,
Contents
FROM
Post
WHERE
Id = ?
';
$resultSet = $pdo->prepare($query);
$resultSet->execute([$_GET['id']]);
$post = $resultSet->fetch();
// Sélection et affichage du template PHTML.
$template = 'edit_post';
include 'layout.phtml';
}
else
{
// Edition d'un article du blog.
$query =
'
UPDATE
Post
SET
Title = ?,
Contents = ?
WHERE
Id = ?
';
$resultSet = $pdo->prepare($query);
$resultSet->execute([$_POST['title'], $_POST['contents'], $_POST['postId']]);
// Retour au panneau d'administration.
header('Location: admin.php');
exit();
}