Skip to content

Instantly share code, notes, and snippets.

@Lartak
Last active March 9, 2019 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lartak/32231b7d9b2fe310d644af9ed838238c to your computer and use it in GitHub Desktop.
Save Lartak/32231b7d9b2fe310d644af9ed838238c to your computer and use it in GitHub Desktop.
Exemple
<?php
session_start();
if (!isset($_SESSION['id'])) {
header('Location: connexion.php'); # Si le membre est pas connecté, on le redirige vers la connexion.php
} elseif (isset($_SESSION['id']) && $_SESSION['grade'] != 'administrateur') {
header('Location: index.php'); # Si le member est conencté, mais il est pas administrateur, on le redirige vers index.php
}
$bdd = new PDO('mysql:host=127.0.0.1;dbname=espace_membre;charset=utf8', 'root', '');
if (isset($_POST['id'], $_POST['ban'], $_POST['secure'])) {
$id = intval($_POST['id']);
$request = $bdd->prepare('UPDATE membres SET ban = ? WHERE id = ?');
if ($request->execute([$_POST['ban'], $id])) {
$message = 'Membre ' . $_POST['ban'] === '0' ? 'banni' : 'dé-banni';
$_SESSION['flash'] = $message;
header('Location: admin.php');
}
}
$members = $bdd->query('SELECT * FROM membres');
if (!empty($_SESSION['flash'])):
echo $_SESSION['flash'];
unset($_SESSION['flash']);
endif; ?>
<table>
<thead>
<tr>
<th>Id</th>
<th>Pseudo</th>
<th>Mail</th>
<th>Grade</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($members as $member): ?>
<tr>
<td><?= $member['id'] ?></td>
<td style="font-weight:bold;"><?= $member['pseudo'] ?></td>
<td><?= $member['mail'] ?></td>
<td><?= $member['grade'] ?></td>
<td>
<form method="POST">
<input type="hidden" name="id" value="<?= $member['id'] ?>">
<input type="hidden" name="ban" value="<?= $member['ban'] === '0' ? '1' : '0' ?>">
<input type="checkbox" name="secure">
<button type="submit"><?= $member['ban'] === '0' ? 'Bannir' : 'Dé-bannir' ?></button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment