-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.php
73 lines (56 loc) · 1.84 KB
/
admin.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
<!DOCTYPE html>
<html>
<head>
<title>ECEpic</title>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="menu.css">
<link rel="stylesheet" type="text/css" href="admin.css">
</head>
<body onkeydown="testEchap(event)">
<?php include('menu.php'); ?>
<?php
try
{
$bdd = new PDO('mysql:host=localhost;dbname=ecepic;charset=utf8', 'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
//récupération de la variable d'URL,
//qui va nous permettre de savoir quel enregistrement supprimer:
$reponse = $bdd->query('SELECT * FROM users');
while ($donnees = $reponse->fetch())
{
if(isset($_POST[$donnees['pseudo']]))
{
$delete_user = $bdd->prepare('DELETE FROM users WHERE pseudo = ?');
$delete_user->execute(array($donnees['pseudo']));
}
if(isset($_POST[$donnees['email']]))
{
$promo_user = $bdd->prepare('UPDATE users SET admin = :admin WHERE email = :email');
$promo_user->execute(array('admin' => 1, 'email' => $donnees['email']));
}
}
echo('<h1>Interface d\'administration</h1>');
echo('<div id="administration">');
$reponse = $bdd->query('SELECT * FROM users');
echo ('<table>');
while ($donnees = $reponse->fetch())
{
echo('<p><tr>');
echo ('<td>');
echo('Utilisateur :'.$donnees['pseudo']);
echo('</td>');
echo('<form method="POST" action="" enctype="multipart/form-data">
<td><input class = "boutton" value="Supprimer" type="submit" name="' . $donnees['pseudo'] . '" /> </td>
<td><input class="boutton" value="Promouvoir" type="submit" name="' . $donnees['email'] . '" /> </td></form></tr></p>');
}
$reponse->closeCursor();
echo('</table>');
echo('</div>');
?>
</body>
</html>