Partage
  • Partager sur Facebook
  • Partager sur Twitter

Ajouter des participants en fonction de la format°

PHP-MySQL

Sujet résolu
    25 octobre 2021 à 6:22:15

    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)

    Et ici, une personne s'occupe d'entrer tous les personnes qui veulent participer aux formations. 

    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.

    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>

    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>
    

    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;
            }   
    
        }
        ?>




    • Partager sur Facebook
    • Partager sur Twitter

    Ajouter des participants en fonction de la format°

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    • Editeur
    • Markdown