Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.8 kB
4
Indexable
Never
<?php
$username = "root";
$password = "";
$database = new PDO("mysql:host=localhost;dbname=formation;", $username, $password);

if (!$database) {
    die('Échec de la connexion à la base de données');
}

$nom = $_POST['nom'];
$prenom = $_POST['prenom'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$motDePasse = $_POST['motDePasse'];
$confirmerMotDePasse = $_POST['confirmerMotDePasse'];

if ($motDePasse !== $confirmerMotDePasse) {
    echo 'Les mots de passe ne correspondent pas,pour recreer le compte';
    echo '<a href="inscription.html">Cliquez ici</a>';
    exit();
}

function generateUniqueIDP($database, $length = 6)
{
    $characters = '0123456789';

    do {
        $idp = '';
        for ($i = 0; $i < $length; $i++) {
            $idp .= $characters[rand(0, strlen($characters) - 1)];
        }

        $existingIDPQuery = $database->prepare("SELECT COUNT(*) FROM participant WHERE IDP = ?");
        $existingIDPQuery->execute([$idp]);
        $count = $existingIDPQuery->fetchColumn();
    } while ($count > 0);

    return $idp;
}

$idp = generateUniqueIDP($database, 6);

function generateUniqueID_Connexion($database, $length = 6)
{
    $characters = '0123456789';

    do {
        $idc = '';
        for ($i = 0; $i < $length; $i++) {
            $idc .= $characters[rand(0, strlen($characters) - 1)];
        }

        $existingIDPQuery = $database->prepare("SELECT COUNT(*) FROM connexion WHERE ID_Connexion = ?");
        $existingIDPQuery->execute([$idc]);
        $count = $existingIDPQuery->fetchColumn();
    } while ($count > 0);

    return $idc;
}

$idc = generateUniqueIDP($database, 6);


$requeteParticipant = $database->prepare("INSERT INTO participant (IDP, nomP, prenomP, emailP, teleP) VALUES (?, ?, ?, ?, ?)");
$requeteConnexion = $database->prepare("INSERT INTO connexion (ID_connexion, IDP, MotDePasse, etat) VALUES (?, ?, ?, false)");

$resultatParticipant = $requeteParticipant->execute([$idp, $nom, $prenom, $email, $telephone]);

if ($resultatParticipant !== false && $requeteParticipant->rowCount() > 0) {
    // Insertion réussie dans la table "participant"
    $resultatConnexion = $requeteConnexion->execute([$idc, $idp, $motDePasse]);

    if ($resultatConnexion !== false && $requeteConnexion->rowCount() > 0) {
        // Insertion réussie dans la table "connexion"
        header("Location: verification.html");
        
    } else {
        // Erreur lors de l'insertion dans la table "connexion"
        echo 'Erreur lors de l\'inscription';
        header("Location: inscription.html"); // Redirection vers la page d'inscription
        exit();
    }
} else {
    // Erreur lors de l'insertion dans la table "participant"
    echo 'Erreur lors de l\'inscription';
}
Leave a Comment