Code : Tout sélectionner
<?php
$bdd = new PDO('mysql:host=localhost;dbname=espace_membre', 'root', '');
if(isset($_POST['forminscription']))
{
$pseudo = htmlspecialchars($_POST['pseudo']);
$mail = htmlspecialchars($_POST['mail']);
$mail2 = htmlspecialchars($_POST['mail2']);
$mdp = sha1($_POST['mdp']);
$mdp2 = sha1($_POST['mdp2']);
if(!empty($_POST['pseudo']) AND !empty($_POST['mail']) AND !empty($_POST['mail2']) AND !empty($_POST['mdp']) AND !empty($_POST['mdp2']))
{
$pseudolength = strlen($pseudo);
if($pseudolength <= 255)
{
if($mail == $mail2)
{
if(filter_var($mail, FILTER_VALIDATE_EMAIL))
{
if($mdp == $mdp2)
{
$insertmbr = $bdd->prepare("INSERT INTO membres(pseudo, mail, motdepasse) VALUES(?, ?, ?)");
$insertmbr->execute(array($pseudo, $mail, $mdp));
$erreur = "Votre compte a bien été crée.";
}
else
{
$erreur = "Vos mots de passe ne correspondent pas.";
}
}
else
{
$erreur = "Votre adresse e-mail n'est pas valide.";
}
}
else
{
$erreur = "Vos adresses e-mail ne correspondent pas.";
}
}
else
{
$erreur = "Votre pseudo ne doit pas dépasser 255 caractères.";
}
}
else
{
$erreur = "Tous les champs doivent être complétés.";
}
}
?>
<html>
<head>
<title>TUTO PHP</title>
<meta charset="utf-8">
</head>
<body>
<div align="center">
<h2><u>S'inscrire</u></h2>
<br>
<form method="POST" action="">
<table>
<tr>
<td align="right">
<label for="pseudo"><u>Pseudo:</u></label>
</td>
<td>
<input type="text" placeholder="Entrez un pseudo" name="pseudo" id="pseudo" size="11" value="<?php if(isset($pseudo)) { echo $pseudo; }?>">
</td>
</tr>
<tr>
<td align="right">
<label for="mail"><u>Mail:</u></label>
</td>
<td>
<input type="email" placeholder="Entrez une adresse e-mail" name="mail" id="mail" size="19" value="<?php if(isset($mail)) { echo $mail; }?>">
</td>
</tr>
<tr>
<td align="right">
<label for="mail2"><u>Confirmation du Mail:</u></label>
</td>
<td>
<input type="email" placeholder="Confirmez votre adresse e-mail" name="mail2" id="mail2" size="23" value="<?php if(isset($mail2)) { echo $mail2; }?>">
</td>
</tr>
<tr>
<td align="right">
<label for="mdp"><u>Mot de passe:</u></label>
</td>
<td>
<input type="password" placeholder="Entrez un mot de passe" name="mdp" id="mdp" size="16">
</td>
</tr>
<tr>
<td align="right">
<label for="mdp2"><u>Confirmation du Mot de passe:</u></label>
</td>
<td>
<input type="password" placeholder="Confirmez votre mot de passe" name="mdp2" id="mdp2" size="22">
</td>
</tr>
<tr>
<td></td>
<td>
<br>
<input type="submit" value="Valider" name="forminscription">
</td>
</tr>
</table>
</form>
<?php
if(isset($erreur))
{
echo '<font color="red">'.$erreur."</font>";
}
?>
</div>
</body>
</html>