-
Notifications
You must be signed in to change notification settings - Fork 0
/
inscription.php
28 lines (24 loc) · 1.13 KB
/
inscription.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
<?php
// initialisation session + BDD
session_start();
include('credentials.php');
$mysqli = new mysqli(DATABASE_ADDRESS, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME);
if ($mysqli->connect_errno)
exit('Erreur de connexion côté serveur, veuillez réessayer plus tard');
// Vérification des données envoyées
if (!isset($_POST["pseudo"], $_POST["prenom"], $_POST["nom"], $_POST["email"], $_POST["mdp"]))
exit("need all fields");
$pseudo = mysqli_real_escape_string($mysqli, $_POST["pseudo"]);
$prenom = mysqli_real_escape_string($mysqli, $_POST["prenom"]);
$nom = mysqli_real_escape_string($mysqli, $_POST["nom"]);
$email = mysqli_real_escape_string($mysqli, $_POST["email"]);
$mdp = mysqli_real_escape_string($mysqli, hash("sha256", $_POST["mdp"]));
// Inscription
$result = $mysqli->query("SELECT * FROM utilisateurs WHERE pseudo = '".$pseudo."' OR email = '".$email."'");
if ($result->num_rows !== 0)
exit("invalid");
$mysqli->query("INSERT INTO utilisateurs (pseudo, prenom, nom, email, mdp) VALUES ('$pseudo', '$prenom', '$nom', '$email', '$mdp')");
$_SESSION["pseudo"] = $pseudo;
$_SESSION["mdp"] = $mdp;
exit("success");
?>