-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreer_compte.php
More file actions
56 lines (47 loc) · 1.96 KB
/
Copy pathcreer_compte.php
File metadata and controls
56 lines (47 loc) · 1.96 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
54
55
56
<?php
require_once('connexion.php');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (
isset($_POST['nom']) && $_POST['nom'] !== "" &&
isset($_POST['prenom']) && $_POST['prenom'] !== "" &&
isset($_POST['login']) && $_POST['login'] !== "" &&
isset($_POST['motdepasse']) && $_POST['motdepasse'] !== "" /* &&
isset($_POST['photo']) && $_POST['photo'] !== "" */
) {
$nom = $_POST['nom'];
$prenom = $_POST['prenom'];
$login = $_POST['login'];
$motdepasse = $_POST['motdepasse'];
$motdepassehash = password_hash($motdepasse, PASSWORD_DEFAULT);
// ✅ Vérifier si le mail existe déjà
$sql = "SELECT * FROM utilisateurs WHERE login = ?";
$stmt = $db->prepare($sql);
$stmt->execute([$login]);
$existant = $stmt->fetch(PDO::FETCH_ASSOC);
if ($existant) {
echo "Erreur : cet email est déjà utilisé.";
echo "<br><a href='login.php'>Retour</a>";
exit;
}
// ✅ Gestion de l’image (facultative)
$photo = "images/default.jpg";
if (isset($_FILES['photo']) && $_FILES['photo']['error'] == 0) {
$dossier = "images/";
$nomFichier = basename($_FILES['photo']['name']);
$chemin = $dossier . $nomFichier;
move_uploaded_file($_FILES['photo']['tmp_name'], $chemin);
$photo = $chemin;
}
// ✅ Insertion en base
$sql = "INSERT INTO utilisateurs (nom, prenom, login, motdepasse, etatbooleen, photo)
VALUES (?, ?, ?, ?, 0, ?)";
$stmt = $db->prepare($sql);
$stmt->execute([$nom, $prenom, $login, $motdepassehash, $photo]);
echo "Compte créé avec succès ✅";
echo "<br><a href='login.php'>Retour à la page de connexion</a>";
exit;
}
echo "Erreur : tous les champs doivent être remplis.";
echo "<br><a href='javascript:history.back()'>Retour</a>";
}
?>