Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: Prenoult
- * Date: 15/11/2016
- * Time: 13:18
- */
- // Connexion
- $connection = new PDO("mysql:host=localhost;dbname=registration", "root", "root");
- // Verification des champs du formulaire
- if (empty($_POST['id']) || empty($_POST['password']) || empty($_POST['passwordConf']) || empty($_POST['email'])) {
- echo "Veuillez renseigner tout les champs<br/>";
- } else {
- if (strlen($_POST['id']) >= 4) {
- if(!checkUsername($_POST['id'])) {
- $id = $_POST['id'];
- }
- else echo "Cet identifiant est indisponible<br/>";
- } else echo "Votre identifiant doit contenir au moins 4 caractères.<br/>";
- if (strlen($_POST['password']) >= 8) {
- $password = $_POST['password'];
- } else echo "Votre mot de passe doit contenir au moins 8 caractères.<br/>";
- if ($_POST['password'] == $_POST['passwordConf']) {
- $passwordConf = $_POST['passwordConf'];
- } else echo "Votre confirmation doit être identique.<br/>";
- if (strstr($_POST['email'], "@") && strstr($_POST['email'], ".")) {
- $email = $_POST['email'];
- } else echo "Votre adresse email est invalide.<br/>";
- if (count($_POST['music']) >= 2) {
- $music = $_POST['music'];
- } else echo "Veuillez cocher au moins 2 genres<br/>";
- }
- function checkUsername($username)
- {
- global $connection;
- $res = true;
- $query = "SELECT COUNT(*) FROM users WHERE name = ?";
- $statement = $connection->prepare($query);
- $statement->bindValue(1, $username, PDO::PARAM_STR);
- $statement->execute();
- if ($statement->fetchAll()[0] != 0) $res = false;
- return $res;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement