Ajouter des personnes dans une formation

Résolu/Fermé
chrisCL974 Messages postés 63 Date d'inscription jeudi 30 septembre 2021 Statut Membre Dernière intervention 25 novembre 2021 - 22 oct. 2021 à 07:27
chrisCL974 Messages postés 63 Date d'inscription jeudi 30 septembre 2021 Statut Membre Dernière intervention 25 novembre 2021 - 25 oct. 2021 à 12:38
Bonjour, j'ai un projet en PHP sur organiser des formations.
Intro : les admin créent des programmes(matières) et à partir de ces programmes, ils organisent des formations(cours)

Le problème ici c'est que je n'arrive pas à renvoyer les données du formulaire où on peut inscrire les données des participants par rapport à la formation qu'il a choisi.

Voici mon fichier pour créer les participants participants.php :
    <?php 
        class participant {

            private $server = "localhost";
            private $username = "root";
            private $password = "";
            private $db = "formation_db";
            private $conn;

            public function __construct()
            { 
                try {
                    $this->conn = new mysqli(
                                    $this->server, 
                                    $this->username, 
                                    $this->password,
                                    $this->db 
                                );
            }   catch(Exception $e) 
            {
                echo "Erreur de connexion" . $e->getMessage();
            }
        }

        function participant(){
            if(isset($_POST['nomParticipant']) && isset($_POST['prenomParticipant']) && isset($_POST['fonctionParticipant']) && isset($_POST['serviceParticipant'])) {
                $nomParticipant = $_POST['nomParticipant'];
                $prenomParticipant = $_POST['prenomParticipant'];
                $fonctionParticipant = $_POST['fonctionParticipant'];
                $serviceParticipant = $_POST['serviceParticipant'];

                if(empty($nomParticipant)) {
                    header('Location: index_demandeur.php?error=Nom du participant requis');
                    exit();
                } else {
                    $query = "INSERT INTO participant (nomParticipant, prenomParticipant, fonctionParticipant, serviceParticipant) 
                    VALUES ('$nomParticipant', '$prenomParticipant', '$fonctionParticipant', '$serviceParticipant')";
                    if($sql = $this->conn->query($query)) {

                        echo "     
                        <head>
                            <meta charset='utf-8'>
                            <meta name='viewport' content='width=device-width,initial-scale=1.0'>
                            <title>Form&nou - Participer</title>
                            <!-- CSS only -->
                            <link href='https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css' rel='stylesheet' integrity='sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We' crossorigin='anonymous'>
                            <link rel='stylesheet' href='https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css' integrity='sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T' crossorigin='anonymous'>
                            <link href='https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css'>
                            <script src='https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js'></script>
                            <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>
                            <script src='https://kit.fontawesome.com/6c1ecc43dd.js' crossorigin='anonymous'></script>
                            <link rel='stylesheet' href='../Public/css/style.css'>
                            <link rel='stylesheet' href='../Public/css/style_admin.css'>
                            <link rel='stylesheet' href='../Public/css/header.css'>
                            <link rel='preconnect' href='https://fonts.googleapis.com'>
                            <link rel='preconnect' href='https://fonts.gstatic.com' crossorigin>
                            <link href='https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap' rel='stylesheet'>
                    
                            <link href='https://fonts.googleapis.com/css?family=Roboto:300,400&display=swap' rel='stylesheet'>
                            <link href='https://fonts.googleapis.com/css?family=Poppins:300,400,500&display=swap' rel='stylesheet'>
                            <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js'></script>
                            <script src='https://cdn.jsdelivr.net/momentjs/2.14.1/moment.min.js'></script>
                            <script src='https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js'>
                            <link rel='stylesheet' href='../fonts/icomoon/style.css'>
                            <link rel='stylesheet' href='../Public/css/rome.css'>
                            <link rel='shortcut icon' type='image/png' href='../Public/img/bg.png'/>
                            <script src='https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js'></script>
                            <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.min.css'>
                    
                        </head>
                
                        <!-- Header -->
                            <div class='header__otherpage'>
                                <div class='header__texture'></div>
                                <div class='container__1'>
                                    <div class='header__navbar'>
                                        <div class='header__navbar--logo'>
                                            <a style='text-decoration:none' href='../demandeur/apropos_demandeur.php' class='header__navbar--logo-title'>Form&Nou</a>
                                        </div>
                                        <div class='header__navbar--menu'>
                                            <a style='text-decoration:none;color:white' href='../demandeur/index_demandeur.php' class='header__navbar--menu-link'><i class='fas fa-home'></i> Accueil</a>
                                            <a style='text-decoration:none;color:white' href='#' class='header__navbar--menu-link'>Les Participants</a>
                                            <a style='text-decoration:none;color:white' href='../demandeur/seFormer.php' class='header__navbar--menu-link'>Se Former</a>
                                            <a style='text-decoration:none;color:white' href='../demandeur/contact.php' class='header__navbar--menu-link'>Contact</a>
                                            <a style='text-decoration:none;color:white' href='../logout.php' class='header__navbar--menu-link'>Déconnexion</a>
                                            
                                        </div>
                    
                                        <div class='header__navbar-toggle'>
                                            <span class='header__navbar-toggle-icons'></span> 
                                        </div>
                                    </div>
                    
                                </div>
                    
                            </div>
                        <br><br><div class='card w-25' style='padding:20px;color: #FFBC42; margin:auto;'>
                        <h5 style='text-align:center'>
                        <i class='fas fa-check-circle'></i>  <b><q> ".$_POST['nomParticipant']." ".$_POST['prenomParticipant']." </q> 
                        a bien été enregistré pour cette formation</b></h5>
                        <a href='../demandeur/index_demandeur.php' style='color:grey;text-align:center'>Retour vers la page d'accueil</a>
                        </div>";
                        exit();
                    } else {
                        echo "
                        <head>
                            <meta charset='utf-8'>
                            <meta name='viewport' content='width=device-width,initial-scale=1.0'>
                            <title>Form&nou - Participer</title>
                            <!-- CSS only -->
                            <link href='https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css' rel='stylesheet' integrity='sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We' crossorigin='anonymous'>
                            <link rel='stylesheet' href='https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css' integrity='sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T' crossorigin='anonymous'>
                            <link href='https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css'>
                            <script src='https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js'></script>
                            <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>
                            <script src='https://kit.fontawesome.com/6c1ecc43dd.js' crossorigin='anonymous'></script>
                            <link rel='stylesheet' href='../Public/css/style.css'>
                            <link rel='stylesheet' href='../Public/css/style_admin.css'>
                            <link rel='stylesheet' href='../Public/css/header.css'>
                            <link rel='preconnect' href='https://fonts.googleapis.com'>
                            <link rel='preconnect' href='https://fonts.gstatic.com' crossorigin>
                            <link href='https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap' rel='stylesheet'>
                    
                            <link href='https://fonts.googleapis.com/css?family=Roboto:300,400&display=swap' rel='stylesheet'>
                            <link href='https://fonts.googleapis.com/css?family=Poppins:300,400,500&display=swap' rel='stylesheet'>
                            <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js'></script>
                            <script src='https://cdn.jsdelivr.net/momentjs/2.14.1/moment.min.js'></script>
                            <script src='https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js'>
                            <link rel='stylesheet' href='../fonts/icomoon/style.css'>
                            <link rel='stylesheet' href='../Public/css/rome.css'>
                            <link rel='shortcut icon' type='image/png' href='../Public/img/bg.png'/>
                            <script src='https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js'></script>
                            <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.min.css'>
                    
                        </head>
                
                        <!-- Header -->
                            <div class='header__otherpage'>
                                <div class='header__texture'></div>
                                <div class='container__1'>
                                    <div class='header__navbar'>
                                        <div class='header__navbar--logo'>
                                            <a style='text-decoration:none' href='../demandeur/apropos_demandeur.php' class='header__navbar--logo-title'>Form&Nou</a>
                                        </div>
                                        <div class='header__navbar--menu'>
                                            <a style='text-decoration:none;color:white' href='../demandeur/index_demandeur.php' class='header__navbar--menu-link'><i class='fas fa-home'></i> Accueil</a>
                                            <a style='text-decoration:none;color:white' href='#' class='header__navbar--menu-link'>Les Participants</a>
                                            <a style='text-decoration:none;color:white' href='../demandeur/seFormer.php' class='header__navbar--menu-link'>Se Former</a>
                                            <a style='text-decoration:none;color:white' href='../demandeur/contact.php' class='header__navbar--menu-link'>Contact</a>
                                            <a style='text-decoration:none;color:white' href='../logout.php' class='header__navbar--menu-link'>Déconnexion</a>
                                            
                                        </div>
                    
                                        <div class='header__navbar-toggle'>
                                            <span class='header__navbar-toggle-icons'></span> 
                                        </div>
                                    </div>
                    
                                </div>
                    
                            </div>
                        
                        <br><br>
                        <aside class='w-25' style='background-color:white;box-shadow: 0px 4px 8px 0px rgba(0, 0, 0, 0.2);position:relative;
                        border-radius:5px;color:white;padding:10px;margin:auto'>
                            <h5 class='text-danger' style='text-align:center;margin-top:20px'><i class='fas fa-exclamation-triangle'></i> 
                                <b>Un problème est survenu!</b> <br>
                                <a href='../demandeur/index_demandeur.php' style='color:grey;text-align:center;font-size:16px'>Cliquez ici pour vous rediriger</a>
                            </h5>          
                        </aside><br><br><br>";
                        var_dump($_POST);
                        exit();
                    }
                }
            }
        }

        public function viewParticipant($id) {
            $data = null;
            $query = "SELECT participantID, formaChoisi, nomParticipant, prenomParticipant, fonctionParticipant, serviceParticipant FROM participant WHERE participantID = " . $id;
            if($sql = $this->conn->query($query)) {
                while($row = mysqli_fetch_assoc($sql)) {
                    $data[] = $row;
                }
            }
            return $data;   
        }  

        public function getAllParticipantByFormation($id_formation) {
            $data = null;
            $query = "SELECT P.participantID
            ,P.formaChoisi
            ,P.nomParticipant
            ,P.prenomParticipant
            ,P.fonctionParticipant
            ,P.serviceParticipant
            ,F.formaID 
            FROM participant P
            LEFT JOIN forma F ON P.formaChoisi = F.formaID
            ORDER BY formaID ASC
            WHERE formaID = '$id_formation'
            ORDER BY nomParticipant ASC";
            if($sql = $this->conn->query($query)) {
                while($row = mysqli_fetch_assoc($sql)) {
                    $data[] = $row;
                }
            }
            return $data;
        }   

    }
    ?>



Ce code est le formulaire pour ajouter les participants en fonction de la formation choisi participer.php :
<?php 
include '../model/creerForm.php';
include '../model/creerServices.php';
include '../model/participant.php';
$creerForm = new creerForm;
$creerServices = new creerServices;
$participant = new participant;
$rowsall = $creerForm->getAllForm();
$rowsallService = $creerServices->getAllService();

$id = $_REQUEST['participer'];
$row = $creerForm->viewForm($id);
$insert = $participant->participant();
?>
<div class="container-fluid">
        <br><br>
    <div>
        <?php if(!empty($row)) { 
            var_dump($row);?>

        
        <a href="index_demandeur.php"><button class="btn btn-secondary">Retour</button> </a>
        <h1 style="color:#FFBC42;text-align:center;margin-top:-50px" ><b>Participer à la formation</b></h1>
    <?php
    } ?>
    </div>

    <div class="container w-75" style="margin-top: 50px;">
        <div class="card" id="participer">
            <div class="row">
                <div class="col-md-7"><img src="../admin/<?php echo $row[0]['imageProgramme'];?>" class="img-fluid rounded-start" alt="..."></div>

                <div class="col-md-5">   
                    <div class="card-body">  
                        <h3 class="card-title"  style="color:#FFBC42"><?php echo $row[0]['programme']?> </h3>
                        <form action="" method="post" enctype="multipart/form-data" style="margin-top: 30px;">
                            <div class="row">
                                <div class="col">
                                    <div class="form-floating mb-3">
                                        <input name="nomParticipant" id="nomParticipant" 
                                        class="form-control" required aria-label="With textarea" type="text" placeholder="Description du programme">
                                        <label for="floatingInput">Nom</label>
                                    </div>
                                </div>
                                <div class="col">
                                    <div class="form-floating mb-3">
                                        <input name="prenomParticipant" id="prenomParticipant" 
                                        class="form-control" required aria-label="With textarea" type="text" placeholder="Description du programme">
                                        <label for="floatingInput">Prénom</label>
                                    </div>
                                </div>
                            </div>
                            
                            <div class="form-floating mb-3">
                                <input name="fonctionParticipant" id="fonctionParticipant" 
                                class="form-control" required aria-label="With textarea" type="text" placeholder="Description du programme">
                                <label for="floatingInput">Fonction/poste occupé</label>
                            </div>

                            <select class="form-select" name="serviceParticipant" aria-label="Default select example" 
                            id="serviceParticipant" required>
                                <option disabled selected>Service</option>

                                <!-- Service ajouté depuis creerService -->   
                                <optgroup label="Les services ajoutés">
                                    <?php
                                        if(!empty($rowsallService)) {
                                        foreach($rowsallService as $rowService) {
                                    ?>  
                                        <option value="<?php echo $rowService['nomService']?>"><?php echo $rowService['nomService']?></option>
                                    <?php }
                                        }
                                    ?>
                                </optgroup>
                            </select> <br>
                            <a href="../demandeur/index_demandeur.php"><button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Annuler</button></a>
                            <button type="submit" class="btn btn-warning" style="color:white">Inscrire le participant</button>
                            </div>
                        
                        
                        
                        </form>                
                    </div>                    
                </div>

            </div>
            <br><br><br>
            

        </div>

    </div>


Et enfin ce code est la page où on voit la formation créée et que l'on souhaite participer :
 <a href="participer.php?participer=<?php echo $row['formaID']?>" class="btn" 
                    style="color:white;background:#FFBC42"
                    onmouseover="this.style.background='#f1ac2c';this.style.color='white';"
                    onmouseout="this.style.background='#FFBC42';this.style.color='white';">Participer</a>
A voir également:

3 réponses

jordane45 Messages postés 38151 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 2 mai 2024 4 652
22 oct. 2021 à 08:44
Bonjour,

Donc.. si on remet tout dans l'ordre ...
Le dernier code que tu nous montres nous permet d'accéder au second
et le second fait appel au premier..
c'est bien ça ?

Ensuite ... tu dis que ça ne marche pas ... c'est à dire ???

As tu, au moins, mis un var_dump de tes variables POST (avant le IF et dedans...) histoire de voir ce que renvoi ton formulaire ?
ça serait bien de commencer par ça et de nous montrer ce que ça donne.... et de nous dire si au moins tu rentres dans le IF ..

Et puis.. si tu fais du PDO pour tes requêtes SQL il faudrait :
1 - Activer l'affichage des erreurs PDO dans la connexion à la bdd
2 - Utiliser les requêtes préparées
3 - Ecrire CHAQUE requête dans un bloc TRY/CATCH
--->>> Voir exemples ici : https://forums.commentcamarche.net/forum/affich-37584941-php-pdo-gerer-les-erreurs
0
chrisCL974 Messages postés 63 Date d'inscription jeudi 30 septembre 2021 Statut Membre Dernière intervention 25 novembre 2021 1
22 oct. 2021 à 08:49
Oui en effet, le dernier code permet d'accéder au deuxieme, et le deuxieme au premier.
J'ai mit un var_dump après le if : var_dump($row) at ça affiche bien l'id de la formation = formaID

Et lorsque je rentre les données d'un participant, il me dirige vers ce code :
else {
                        echo "
            
                        <aside class='w-25' style='background-color:white;box-shadow: 0px 4px 8px 0px rgba(0, 0, 0, 0.2);position:relative;
                        border-radius:5px;color:white;padding:10px;margin:auto'>
                            <h5 class='text-danger' style='text-align:center;margin-top:20px'><i class='fas fa-exclamation-triangle'></i> 
                                <b>Un problème est survenu!</b> <br>
                                <a href='../demandeur/index_demandeur.php' style='color:grey;text-align:center;font-size:16px'>Cliquez ici pour vous rediriger</a>
                            </h5>          
                        </aside><br><br><br>";
                        var_dump($_POST);
                        exit();
0
jordane45 Messages postés 38151 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 2 mai 2024 4 652 > chrisCL974 Messages postés 63 Date d'inscription jeudi 30 septembre 2021 Statut Membre Dernière intervention 25 novembre 2021
22 oct. 2021 à 09:07
Je ne dois pas écrire français correctement ....

Je disais donc :
Faut mettre un VAR_DUMP de $_POST AVANT ton IF

sous entendu .. le IF dans lequel tu te sers de ces variables .......


Autrement dit :


        function participant(){

            var_dump($_POST);
            if(isset($_POST['nomParticipant']) && isset($_POST['prenomParticipant']) && isset($_POST['fonctionParticipant']) && isset($_POST['serviceParticipant'])) {
                $nomParticipant = $_POST['nomParticipant'];
                $prenomParticipant = $_POST['prenomParticipant'];
                $fonctionParticipant = $_POST['fonctionParticipant'];
                $serviceParticipant = $_POST['serviceParticipant'];


0
chrisCL974 Messages postés 63 Date d'inscription jeudi 30 septembre 2021 Statut Membre Dernière intervention 25 novembre 2021 1 > jordane45 Messages postés 38151 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 2 mai 2024
22 oct. 2021 à 09:10
0
jordane45 Messages postés 38151 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 2 mai 2024 4 652 > chrisCL974 Messages postés 63 Date d'inscription jeudi 30 septembre 2021 Statut Membre Dernière intervention 25 novembre 2021
22 oct. 2021 à 09:45
Donc ton $_POST est vide ....
As tu rempli le formulaire puis cliqué sur le bouton pour l'envoyer avant de nous faire cette capture d'écran??
par ce que .. sinon..ça ne nous sert à rien...
0
chrisCL974 Messages postés 63 Date d'inscription jeudi 30 septembre 2021 Statut Membre Dernière intervention 25 novembre 2021 1 > jordane45 Messages postés 38151 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 2 mai 2024
22 oct. 2021 à 09:46
Oui j'ai rempli le formulaire mais ça n'enregistre pas et le formaChoisi n'a pas été ajouté quand le participant a remplit le formulaire de la formation choisie
0
chrisCL974 Messages postés 63 Date d'inscription jeudi 30 septembre 2021 Statut Membre Dernière intervention 25 novembre 2021 1
22 oct. 2021 à 10:30


Avec ce code:
        function participant(){
                //récupération PROPRE des variables AVANT de les utiliser
                $nomParticipant = isset($_POST['nomParticipant']) ? $_POST['nomParticipant'] : NULL;
                $prenomParticipant = isset($_POST['prenomParticipant']) ? $_POST['prenomParticipant'] : NULL;
                $fonctionParticipant = isset($_POST['fonctionParticipant']) ? $_POST['fonctionParticipant'] : NULL;
                $serviceParticipant = isset($_POST['serviceParticipant']) ? $_POST['serviceParticipant'] : NULL;

                echo "<br>POST (avant if) <br>";
                var_dump($_POST);
                //if(isset($_POST['nomParticipant']) && isset($_POST['prenomParticipant']) && isset($_POST['fonctionParticipant']) && isset($_POST['serviceParticipant'])) {
                //    $nomParticipant = $_POST['nomParticipant'];
                //    $prenomParticipant = $_POST['prenomParticipant'];
                //    $fonctionParticipant = $_POST['fonctionParticipant'];
                //    $serviceParticipant = $_POST['serviceParticipant'];

                if($nomParticipant && $prenomParticipant && $fonctionParticipant && $serviceParticipant ) {
                    echo "<br> JE SUIS BIEN ENTRE DANS LE IF ... ";
                    if(empty($nomParticipant)) {
                    //header('Location: index_demandeur.php?error=Nom du participant requis');
                    echo " ERREUR !!!! ";
                    exit();
                    } else {
                    $query = "INSERT INTO participant (nomParticipant, prenomParticipant, fonctionParticipant, serviceParticipant) 
                    VALUES ('$nomParticipant', '$prenomParticipant', '$fonctionParticipant', '$serviceParticipant')";
                    if($sql = $this->conn->query($query)) {

                        echo "     
<div class='card w-25' style='padding:20px;color: #FFBC42; margin:auto;'>
                        <h5 style='text-align:center'>
                        <i class='fas fa-check-circle'></i>  <b><q> ".$_POST['nomParticipant']." ".$_POST['prenomParticipant']." </q> 
                        a bien été enregistré pour cette formation</b></h5>
                        <a href='../demandeur/index_demandeur.php' style='color:grey;text-align:center'>Retour vers la page d'accueil</a>
                        </div>";
                        exit();
                    } else {
                        echo "
 
                        <aside class='w-25' style='background-color:white;box-shadow: 0px 4px 8px 0px rgba(0, 0, 0, 0.2);position:relative;
                        border-radius:5px;color:white;padding:10px;margin:auto'>
                            <h5 class='text-danger' style='text-align:center;margin-top:20px'><i class='fas fa-exclamation-triangle'></i> 
                                <b>Un problème est survenu!</b> <br>
                                <a href='../demandeur/index_demandeur.php' style='color:grey;text-align:center;font-size:16px'>Cliquez ici pour vous rediriger</a>
                            </h5>          
                        </aside><br><br><br>";
                        exit();
                    }
                    
                }
            }
        }
0
jordane45 Messages postés 38151 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 2 mai 2024 4 652
22 oct. 2021 à 11:20
Je constate que tu n'as toujours pas appliqué les modifications demandées concernant l'exécution de ta requête .....
Le problème s'y trouve visiblement...
Tu es bien en PDO ??

Si oui, applique ceci :
https://forums.commentcamarche.net/forum/affich-37584941-php-pdo-gerer-les-erreurs
0
chrisCL974 Messages postés 63 Date d'inscription jeudi 30 septembre 2021 Statut Membre Dernière intervention 25 novembre 2021 1 > jordane45 Messages postés 38151 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 2 mai 2024
Modifié le 22 oct. 2021 à 13:20
J'ai suivi comme dans l'activation des erreurs
PDO :
public function __construct()
            { 
                try {
                    $this->conn = new mysqli(
                                    $this->server, 
                                    $this->username,    
                                    $this->password,
                                    $this->db);
            } catch(Exception $e) {
                die("Erreur de connexion" . $e->getMessage());
            }


function participant(){
                //récupération PROPRE des variables AVANT de les utiliser
                $nomParticipant = isset($_POST['nomParticipant']) ? $_POST['nomParticipant'] : NULL;
                $prenomParticipant = isset($_POST['prenomParticipant']) ? $_POST['prenomParticipant'] : NULL;
                $fonctionParticipant = isset($_POST['fonctionParticipant']) ? $_POST['fonctionParticipant'] : NULL;
                $serviceParticipant = isset($_POST['serviceParticipant']) ? $_POST['serviceParticipant'] : NULL;

                echo "<br>POST (avant if) <br>";
                var_dump($_POST);
                //if(isset($_POST['nomParticipant']) && isset($_POST['prenomParticipant']) && isset($_POST['fonctionParticipant']) && isset($_POST['serviceParticipant'])) {
                //    $nomParticipant = $_POST['nomParticipant'];
                //    $prenomParticipant = $_POST['prenomParticipant'];
                //    $fonctionParticipant = $_POST['fonctionParticipant'];
                //    $serviceParticipant = $_POST['serviceParticipant'];

                if($nomParticipant && $prenomParticipant && $fonctionParticipant && $serviceParticipant ) {
                    echo "<br> JE SUIS BIEN ENTRE DANS LE IF ... ";
                    if(empty($nomParticipant)) {
                    //header('Location: index_demandeur.php?error=Nom du participant requis');
                    echo " ERREUR !!!! ";
                    exit();
                    } else {
                    $query = "INSERT INTO participant (nomParticipant, prenomParticipant, fonctionParticipant, serviceParticipant) 
                    VALUES ('$nomParticipant', '$prenomParticipant', '$fonctionParticipant', '$serviceParticipant')";
                    $datas = array('nomParticipant'=>$nomParticipant, 'prenomParticipant'=>$prenomParticipant, 'fonctionParticipant'=>$fonctionParticipant, 'serviceParticipant'=>$serviceParticipant);

                    try{
                        $requete = $this->conn->prepare($query) ;
                        $requete->execute($datas) ;
                    }catch(Exception $e){
                        // en cas d'erreur :
                            echo " Erreur ! ".$e->getMessage();
                            echo " Les datas : " ;
                        print_r($datas);
                        }


L'erreur :
0
jordane45 Messages postés 38151 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 2 mai 2024 4 652 > chrisCL974 Messages postés 63 Date d'inscription jeudi 30 septembre 2021 Statut Membre Dernière intervention 25 novembre 2021
22 oct. 2021 à 14:06
purée.... tu n'es pas en PDO .. mais en mysqli !!!!
c'est donc les exemples fournis ici que tu dois suivre
https://www.php.net/manual/fr/mysqli.error.php
0
chrisCL974 Messages postés 63 Date d'inscription jeudi 30 septembre 2021 Statut Membre Dernière intervention 25 novembre 2021 1 > jordane45 Messages postés 38151 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 2 mai 2024
23 oct. 2021 à 18:58
J'ai suivi l'exmeple
0
jordane45 Messages postés 38151 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 2 mai 2024 4 652 > chrisCL974 Messages postés 63 Date d'inscription jeudi 30 septembre 2021 Statut Membre Dernière intervention 25 novembre 2021
23 oct. 2021 à 20:33
Et donc.. à quoi ressemble ton code maintenant ?
0
jordane45 Messages postés 38151 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 2 mai 2024 4 652
25 oct. 2021 à 08:07
Nan, mais faut être cohérant dans les codes que tu écris...
Et vérifier que la connexion fonctionne est la première chose à faire ... quelque soit le code ...

Donc, dans ta connexion
public function __construct()
{ 

    $this->conn = new mysqli(
        $this->server, 
        $this->username,    
        $this->password,
        $this->db);
      /* Vérification de la connexion */
    if ($this->conn->connect_errno) {
        printf("Échec de la connexion: %s\n", $this->conn->connect_error);
        exit();
    }
   
}


Ensuite.. il reste l'exécution de ta requête ...
Là .. tu as copié tel quel l'exemple du site au lieu de l'adapter à tes besoins...
Normal donc que ça t'affiche une erreur !!!

Donc
 if (!$this->conn->query("SET a=1")) {
                        printf("Message d'erreur : %s\n", $this->conn->error);
                    }

A corriger par
//voir : https://www.php.net/manual/fr/mysqli.real-escape-string.php
$query = "INSERT INTO participant (nomParticipant, prenomParticipant, fonctionParticipant, serviceParticipant) 
          VALUES ('".$this->conn->real_escape_string($nomParticipant)."', 
          '".$this->conn->real_escape_string($prenomParticipant)."', 
          '".$this->conn->real_escape_string($fonctionParticipant)."',
          '".$this->conn->real_escape_string($serviceParticipant)."')";

if (!$this->conn->query($query)) {
  echo "<br>Erreur dans la requête " . $query ." <br>". $this->conn->error;
  exit();
}


bref... faut pas coller bêtement.. mais ADAPTER tes codes aux exemples trouvés sur le net !!
0
chrisCL974 Messages postés 63 Date d'inscription jeudi 30 septembre 2021 Statut Membre Dernière intervention 25 novembre 2021 1
25 oct. 2021 à 09:15
0
jordane45 Messages postés 38151 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 2 mai 2024 4 652 > chrisCL974 Messages postés 63 Date d'inscription jeudi 30 septembre 2021 Statut Membre Dernière intervention 25 novembre 2021
25 oct. 2021 à 09:21
et bien voila ... le message d'erreur est assez clair .....
0
chrisCL974 Messages postés 63 Date d'inscription jeudi 30 septembre 2021 Statut Membre Dernière intervention 25 novembre 2021 1 > jordane45 Messages postés 38151 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 2 mai 2024
25 oct. 2021 à 09:29
Mais du coup comment on pourrait envoyer le formulaire par rapport à la formation sélectionnée? De base c'était ça le problème
0
jordane45 Messages postés 38151 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 2 mai 2024 4 652 > chrisCL974 Messages postés 63 Date d'inscription jeudi 30 septembre 2021 Statut Membre Dernière intervention 25 novembre 2021
25 oct. 2021 à 09:45
Et bien tu as l'information dans l' url lorsque tu affiche le formulaire ?
Tu peux donc ajouter, dans ce formulaire, un input de type hidden contenant la valeur qui se trouve dans l'url.
Grâce à ça, l'information sera envoyé en $_POST de la même façon que les autres données.
0
chrisCL974 Messages postés 63 Date d'inscription jeudi 30 septembre 2021 Statut Membre Dernière intervention 25 novembre 2021 1 > jordane45 Messages postés 38151 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 2 mai 2024
Modifié le 25 oct. 2021 à 10:18
Un input comme ça?
Button qui envoie le formulaire :
<button class="btn btn-warning" style="color:white">
<input type="hidden" value="<?php echo $row[0]['formaID']?>">Inscrire le participant</input>
</button>


Ajout du participant :
function participant(){
                $nomParticipant = isset($_POST['nomParticipant']) ? $_POST['nomParticipant'] : NULL;
                $prenomParticipant = isset($_POST['prenomParticipant']) ? $_POST['prenomParticipant'] : NULL;
                $fonctionParticipant = isset($_POST['fonctionParticipant']) ? $_POST['fonctionParticipant'] : NULL;
                $serviceParticipant = isset($_POST['serviceParticipant']) ? $_POST['serviceParticipant'] : NULL;

                if($nomParticipant && $prenomParticipant && $fonctionParticipant && $serviceParticipant ) {
                    echo "<br> JE SUIS BIEN ENTRE DANS LE IF ... ";
                    if(empty($nomParticipant)) {
                    //header('Location: index_demandeur.php?error=Nom du participant requis');
                    echo " ERREUR !!!! ";
                    exit();
                    } else {
                    $query = "INSERT INTO participant (nomParticipant, prenomParticipant, fonctionParticipant, serviceParticipant) 
                            VALUES ('".$this->conn->real_escape_string($nomParticipant)."', 
                            '".$this->conn->real_escape_string($prenomParticipant)."', 
                            '".$this->conn->real_escape_string($fonctionParticipant)."',
                            '".$this->conn->real_escape_string($serviceParticipant)."')";

                    if (!$this->conn->query($query)) {
                    echo "<br>Erreur dans la requête " . $query ." <br>". $this->conn->error;
                    exit();
                    } else {
                        echo "<div class='card w-25' style='padding:20px;color: #FFBC42; margin:auto;'>
                        <h5 style='text-align:center'>
                        <i class='fas fa-check-circle'></i>  <b><q> ".$_POST['nomParticipant']." ".$_POST['prenomParticipant']." </q> 
                        a bien été enregistré pour cette formation</b></h5>
                        <a href='../demandeur/index_demandeur.php' style='color:grey;text-align:center'>Retour vers la page d'accueil</a>
                        </div>";
                        exit();
                    }
0