IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

enregistrement de cases à cocher


Sujet :

Langage PHP

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2008
    Messages : 11
    Points : 17
    Points
    17
    Par défaut enregistrement de cases à cocher
    Bonjour j ai un petit form a faire pour enregistrer les inscrits à une sortie ( pour une assos )

    J ai commencer mon form mais apres plusieurs tests je ne sauve rien ou pas les bonnes infos ds la bdd.

    j ai enlever mon code d enregistrement, a base de foreach il enregistrer toutes

    Mon code est:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    <html><body><?php
    @$action = $_GET['action'];
     
    if ($action=='enregistrer'){
     
    	//on enregistre
    	//champ de la table Mysql
    	//nom
    	//inscription j1
    	//inscription j2
    	foreach ($inscription_j1 as $choix1){
     
    		foreach ($inscription_j2 as $choix2){
    			enregistrer_inscription($_POST['nom'],$choix1,$choix2);
    		}
    	}
     
     
     
     
     
    }else{
    	//le form
    	echo '<form name="test" action="test_checkbox.php?action=enregistrer" method="POST" >';
    	echo '<table>';
    		echo '<tr><td>Nom</td><td>Inscription jour 1</td><td>Inscription jour 2</td></tr>';
    		echo '<tr>';
    			echo '<td width="200"><input type="text" name="nom" value="nicolas" /></td>';
    			echo '<td width="200"><input type="checkbox" name="inscription_j1[]" value="" /></td>';
    			echo '<td width="200"><input type="checkbox" name="inscription_j2[]" value="" /></td>';
    		echo '</tr>';
    		echo '<tr>';
    			echo '<td><input type="text" name="nom" value="stephane" /></td>';
    			echo '<td><input type="checkbox" name="inscription_j1[]" value="" /></td>';
    			echo '<td><input type="checkbox" name="inscription_j2[]" value="" /></td>';
    		echo '</tr>';
    		echo '<tr>';
    			echo '<td><input type="text" name="nom" value="julien" /></td>';
    			echo '<td><input type="checkbox" name="inscription_j1[]" value="" /></td>';
    			echo '<td><input type="checkbox" name="inscription_j2[]" value="" /></td>';
    		echo '</tr>';
    		echo '<tr>';
    			echo '<td><input type="text" name="nom" value="max" /></td>';
    			echo '<td><input type="checkbox" name="inscription_j1[]" value="" /></td>';
    			echo '<td><input type="checkbox" name="inscription_j2[]" value="" /></td>';
    		echo '</tr>';
    		echo '<tr>';
    			echo '<td><input type="text" name="nom" value="sophie" /></td>';
    			echo '<td><input type="checkbox" name="inscription_j1[]" value="" /></td>';
    			echo '<td><input type="checkbox" name="inscription_j2[]" value="" /></td>';
    		echo '</tr>';
    	echo '</table><input type="submit" value="OK" /></form>';
    }
    ?></body></html>

  2. #2
    Membre expérimenté
    Avatar de Mahefasoa
    Homme Profil pro
    Manager IT
    Inscrit en
    Octobre 2003
    Messages
    835
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Madagascar

    Informations professionnelles :
    Activité : Manager IT

    Informations forums :
    Inscription : Octobre 2003
    Messages : 835
    Points : 1 664
    Points
    1 664
    Par défaut
    Bonjour,

    Peux-tu essayer le code suivant?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
     
    <html>
        <body>
            <?php
                @$action = $_GET['action'];
     
                if ($action=='enregistrer'){
                    //on enregistre
                    //champ de la table Mysql
                    //nom
                    //inscription j1
                    //inscription j2
                    $inscription_j1 = $_POST['inscription_j1'];
                    $inscription_j2 = $_POST['inscription_j2'];
                    $nom = $_POST['nom'];
     
                    foreach ($nom as $personne){
                        $choix1 = $choix2 = 0;
                        if (isset($inscription_j1[$personne][0]))
                        {
                            $choix1 = $inscription_j1[$personne][0];
                        }
                        if (isset($inscription_j2[$personne][0]))
                        {
                            $choix2 = $inscription_j2[$personne][0];
                        }
                        //echo $personne.'-'.$choix1.'-'.$choix2.'<br>';
                        enregistrer_inscription($personne,$choix1,$choix2);
                    }
                }else{
            ?>
                <form name="test" action="?action=enregistrer" method="POST" >
                <table>
                    <tr><td>Nom</td><td>Inscription jour 1</td><td>Inscription jour 2</td></tr>
                    <tr>
                        <td width="200"><input type="text" name="nom[]" value="nicolas" /></td>
                        <td width="200"><input type="checkbox" name="inscription_j1[nicolas][]" value="1" /></td>
                        <td width="200"><input type="checkbox" name="inscription_j2[nicolas][]" value="1" /></td>
                    </tr>
                    <tr>
                        <td><input type="text" name="nom[]" value="stephane" /></td>
                        <td><input type="checkbox" name="inscription_j1[stephane][]" value="1" /></td>
                        <td><input type="checkbox" name="inscription_j2[stephane][]" value="1" /></td>
                    </tr>
                    <tr>
                        <td><input type="text" name="nom[]" value="julien" /></td>
                        <td><input type="checkbox" name="inscription_j1[julien][]" value="1" /></td>
                        <td><input type="checkbox" name="inscription_j2[julien][]" value="1" /></td>
                    </tr>
                    <tr>
                        <td><input type="text" name="nom[]" value="max" /></td>
                        <td><input type="checkbox" name="inscription_j1[max][]" value="1" /></td>
                        <td><input type="checkbox" name="inscription_j2[max][]" value="1" /></td>
                    </tr>
                    <tr>
                        <td><input type="text" name="nom[]" value="sophie" /></td>
                        <td><input type="checkbox" name="inscription_j1[sophie][]" value="1" /></td>
                        <td><input type="checkbox" name="inscription_j2[sophie][]" value="1" /></td>
                    </tr>
                </table>
                <input type="submit" value="OK" />
                </form>
            <?php
                }
            ?>
        </body>
    </html>
    Bien cordialement,

Discussions similaires

  1. [AC-2007] Ajouter enregistrements avec cases à cocher
    Par macgyver44 dans le forum VBA Access
    Réponses: 4
    Dernier message: 13/04/2013, 21h37
  2. Selection d'enregistrement avec case à cocher
    Par gelipepetefli dans le forum IHM
    Réponses: 2
    Dernier message: 25/04/2010, 13h37
  3. [AC-2003] Comparaison d'enregistrement par case à cocher
    Par ez29kiel dans le forum IHM
    Réponses: 2
    Dernier message: 24/06/2009, 13h41
  4. [A 03] - Ajout enregistrement par case à cocher
    Par enkoder dans le forum VBA Access
    Réponses: 2
    Dernier message: 19/11/2008, 20h35
  5. [MySQL] Enregistrer une case à cocher sur MySQL
    Par dadou9101 dans le forum PHP & Base de données
    Réponses: 6
    Dernier message: 21/10/2008, 09h35

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo