-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlivre-or.php
executable file
·73 lines (60 loc) · 2.64 KB
/
livre-or.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
session_start();
require_once 'db_connect.php';
$sql = 'SELECT comments.id as id, comment, date, users.login, users.id as user_id FROM comments INNER JOIN users ON comments.user_id = users.id ORDER BY date DESC';
// statement
$select = $pdo->prepare($sql);
$select->execute();
$comments = $select->fetchAll(PDO::FETCH_ASSOC);
if (isset($_POST['delete-comment'])) {
var_dump($_POST);
$sql = 'DELETE FROM comments WHERE id = :id';
$delete = $pdo->prepare($sql);
$delete->execute([
':id' => $_POST['delete-comment']
]);
header('Location: livre-or.php');
}
// At display, format fetched string date to timestamp Unix w/ strtotime, then format it w/ date function
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Les Commentaires | Livre d'Or</title>
<link rel="stylesheet" href="font/webfont.css">
<link rel="stylesheet" href="css/style.css">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<script src="https://kit.fontawesome.com/42d5a324f0.js" crossorigin="anonymous"></script>
</head>
<body>
<?php require_once 'elements/header.php'; ?>
<main>
<div class="container comments-container">
<h2>Vos commentaires</h2>
<hr>
<?php foreach ($comments as $comment) : ?>
<div class="comment">
<div class="pfp-container">
<div class="pfp" style="background-image: url('uploads/pfp/<?= file_exists('uploads/pfp/' . $comment['user_id'] . '_pfp.png') ? $comment['user_id'] . '_pfp.png' : 'default_pfp.png' ?>');"></div>
</div>
<div class="text-container">
<h3>Posté le <?= date('d/m/Y', strtotime($comment['date'])) ?> par <?= $comment['login'] ?></h3>
<p><?= $comment['comment'] ?></p>
</div>
<?php if (isset($_SESSION['is_logged'])): ?>
<?php if ($_SESSION['logged_user_id'] === $comment['user_id'] || $_SESSION['logged_user_id'] == 1): ?>
<form method="post">
<button type="submit" name="delete-comment" class="delete-comment" value="<?= $comment['id'] ?>">Supprimer</button>
</form>
<?php endif ?>
<?php endif ?>
</div>
<?php endforeach ?>
</div>
</main>
<?php require_once 'elements/footer.php' ?>
</body>
</html>