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 :

Récupération des informations d'un checkbox pour traitement php


Sujet :

Langage PHP

  1. #1
    Membre régulier
    Homme Profil pro
    Technicien réseau
    Inscrit en
    Janvier 2010
    Messages
    119
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations professionnelles :
    Activité : Technicien réseau
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Janvier 2010
    Messages : 119
    Points : 77
    Points
    77
    Par défaut Récupération des informations d'un checkbox pour traitement php
    Bonjour à tous,

    j'ai un tableau avec des informations récupérées à travers une requête sql. Je veux faire une sélection de certaines informations à retraiter et à afficher dans un autre tableau à travers un checkbox et l'ID.

    Alors mon souci se situe au niveau de la récupération, je constate que toutes les informations sélectionnées ne sont pas récupérées à travers le checkbox.

    ci-dessous mon code source de la consultation générale avec checkbox :
    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
    68
    69
    70
    71
     
    			// Consultation Generale
     
              if (isset($_POST['Valider']))
    	           {
    			      $Choix  = $_POST['Choix'];
                      //echo $Choix;
    			      if ($Choix == 'Generale')
    	                 {
     
    			      echo '<table><tr>
    				<th> RAM </th>
    				<th> ID </th>
    				<th>DATE </th>
    				<th>PROJETS / TÂCHES</th>
    				<th>DESCRIPTION</th>
    				<th>ETAT D’AVANCEMENT	</th>
    				<th>RESPONSABLE </th>
    				<th>ETAT </th>
    				<th>MODIFIER</th>
    				<th>SUPPRIMER</th>
    				</tr>';
     
    			try
    			{
     
     
    		$date1 = $_POST['date1'];
    		$date2 = $_POST['date2'];
    			 $reponse = $bdd->query("SELECT 
    	 a.id_rah,
         a.datejour,
    	 a.projets_taches,
    	 a.description,
    	 a.avancement,
    	 a.entite_responsable,
    	 a.etat_tache
         FROM 
         rah a
    	 where datejour between '$date1' and '$date2' order by a.datejour");
     
    			while ($donnees = $reponse->fetch())
    			{
    				$i++;
    				echo '<tr>';
    					echo '
     
    					<td><input type="checkbox" name="checkbox[]" id ="checkbox" value ="<?php echo '.$donnees['id_rah'].'?>" /></td>
    					<td>'. $donnees['id_rah'].'</td>
    					<td>'. $donnees['datejour'].'</td>
    					<td>'. $donnees['projets_taches'].'</td>
    					<td>'. $donnees['description'].'</td>
    					<td>'. $donnees['avancement'].'</td>
    					<td>'. $donnees['entite_responsable'].'</td>
    					<td>'. $donnees['etat_tache'].'</td>';
    					echo'<td><a href="modifier_rah.php?modifier='.$donnees['id_rah'].'">Modifier</a></td>';
    					echo'<td><a href="confirmation_sup_rah.php?supprimer='.$donnees['id_rah'].'"><img src="images/supprimer.jpg"></a></td>';
    				echo '</tr>';
     
    			}
     
    			}
    			catch(Exception $e)
                {
                     die('Erreur : '.$e->getMessage());
                }
     
    			   }
     
     
    			   echo '</table>';
    J'ai fait un et il me renvoie la valeur NULL.

    ci-dessous mon code source pour affichage du deuxième tableau :

    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
     
    var_dump($_POST['checkbox']);
    			   if (isset($_POST['checkbox']))
                   { 
    			     $checkbox = $_POST['checkbox'];
    			     echo '<table><tr>
    				<th>DATE </th>
    				<th>PROJETS / TÂCHES</th>
    				<th>DESCRIPTION</th>
    				<th>ETAT D’AVANCEMENT	</th>
    				<th>RESPONSABLE </th>
    				<th>ETAT </th>
    				</tr>';
     
    				//recupérer ces valeurs dans un array
                     $tabCheckbox = ($_POST['checkbox']);
                     foreach ($tabCheckbox as $checkbox) 
    				 {
                     $checkbox[] = addslashes($checkbox);
                     $reponse = $bdd->query("SELECT 
    	             a.id_rah,
    				 a.datejour,
    				 a.projets_taches,
    				 a.description,
    				 a.avancement,
    				 a.entite_responsable,
    				 a.etat_tache
    				 FROM 
    				 rah a 
    				 where a.datejour = '$checkbox' order by a.datejour");
     
    				$donnees = $reponse->fetch();
    				$i++;
    				echo '<tr>';
    					echo '
    					<td>'. $donnees['datejour'].'</td>
    					<td>'. $donnees['projets_taches'].'</td>
    					<td>'. $donnees['description'].'</td>
    					<td>'. $donnees['avancement'].'</td>
    					<td>'. $donnees['entite_responsable'].'</td>
    					<td>'. $donnees['etat_tache'].'</td>';
    				echo '</tr>';
    				}
     
                   }
    Comme je l'ai dit plus haut le var_dump($_POST['checkbox']); me renvoie un résultat NULL et donc la requête du deuxième code ne renvoie rien.


    Alors je veux savoir si j'affiche bien mon id-rah ?

    merci pour vos reponses.

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Ou est le formulaire ?

    Au passage : on n'utilise pas addslashes() en PDO (ni même avec l'extension mysql d'ailleurs), on utilise des requêtes préparées, surtout si tu fais des requêtes répétées.

  3. #3
    Membre régulier
    Homme Profil pro
    Technicien réseau
    Inscrit en
    Janvier 2010
    Messages
    119
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations professionnelles :
    Activité : Technicien réseau
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Janvier 2010
    Messages : 119
    Points : 77
    Points
    77
    Par défaut
    Bonjour sabotage,
    Formulaire pour la recherche periodique
    Code html : 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
    <div id="titre_tab">CONSULTATION DES RAPPORTS D'ACTIVITES HEBDOMADAIRES
    <form method="POST" action="consultation_rah.php" name="consultation_rah" onSubmit="return verifier();return verif(formule)" enctype="multipart/form-data" >
    <div id="fieldset1">
    <fieldset style="width:360px;">
           <legend><strong>SELECTIONNER</strong></legend> 
    	    <p>
    		 <label for="id"><strong>Date 1 : </strong> </label>
             <input type="date" name="date1" id="date1" tabindex="10" /><br />
    		 <label for="id"><strong>Date 2 : </strong> </label>
             <input type="date" name="date2" id="date2" tabindex="10" /><br /><br />
    		 <input type="radio" name="Choix" value="Generale" checked>Generale
    		 <input type="radio" name="Choix" value="Suivi">Suivi
    		 <input type="radio" name="Choix" value="Conclu">Termin&eacute;es
            </p>
    </fieldset>
    </div>
    <fieldset id="consul" style="width:360px;">
           <legend><strong>OPTIONS</strong></legend> 
    	    <p>
    		<input type="submit" name="Valider" id="Valider" value="Valider" /> 
    	   <input type="submit" name="Annuler" id="Annuler" value="Annuler" />  
            </p>
    </fieldset> <br/>
    </form>	
    </div>

    Ensuite je fais une requête pour m'afficher le premier tableau.

    Requête + code php :
    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
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    <?php
    include("connection_gescompta.php");
     $i=0;
    //**************************************************************************************************************************************			
    // Consultation Generale
    if (isset($_POST['Valider']))
    {
          $Choix  = $_POST['Choix'];
          //echo $Choix;
          if ($Choix == 'Generale')
          {
    	      echo '<table><tr>
    		<th> RAM </th>
    		<th> ID </th>
    		<th>DATE </th>
    		<th>PROJETS / TÂCHES</th>
    		<th>DESCRIPTION</th>
    		<th>ETAT D’AVANCEMENT	</th>
    		<th>RESPONSABLE </th>
    		<th>ETAT </th>
    		<th>MODIFIER</th>
    		<th>SUPPRIMER</th>
    		</tr>';
    	try
    	{
    		$date1 = $_POST['date1'];
    		$date2 = $_POST['date2'];
    		$reponse = $bdd->query("SELECT 
    	 a.id_rah,
         a.datejour,
    	 a.projets_taches,
    	 a.description,
    	 a.avancement,
    	 a.entite_responsable,
    	 a.etat_tache
         FROM 
         rah a
    	 where datejour between '$date1' and '$date2' order by a.datejour");
    		while ($donnees = $reponse->fetch())
    		{
    			$i++;
    			echo '<tr>';
    				echo '
    				<td><input type="checkbox" name="checkbox[]" id ="checkbox" value ="<?php echo '.$donnees['id_rah'].'?>" /></td>
    				<td>'. $donnees['id_rah'].'</td>
    				<td>'. $donnees['datejour'].'</td>
    				<td>'. $donnees['projets_taches'].'</td>
    				<td>'. $donnees['description'].'</td>
    				<td>'. $donnees['avancement'].'</td>
    				<td>'. $donnees['entite_responsable'].'</td>
    				<td>'. $donnees['etat_tache'].'</td>';
    				echo'<td><a href="modifier_rah.php?modifier='.$donnees['id_rah'].'">Modifier</a></td>';
    				echo'<td><a href="confirmation_sup_rah.php?supprimer='.$donnees['id_rah'].'"><img src="images/supprimer.jpg"></a></td>';
    				echo '</tr>';
    		}
    	}
    	catch(Exception $e)
            {
                    die('Erreur : '.$e->getMessage());
            }
    }
    echo '</table>';
    echo '</table>';
    /******************************************************/
    /*********Formulaire de validation des informations après checkbox***/
     
    			 echo '<form method="POST" action="consultation_rah.php" name="consultation_rah" enctype="multipart/form-data" >';
    			 echo ' <br/> <br/> <br/>';
    			 echo '<fieldset id="consul_ram" style="width:360px;">';
    			 echo ' <legend><strong>OPTIONS</strong></legend> ';
    			 echo '<p>';
    			 echo '<input type="submit" name="generer_ram" id="generer_ram" value="RAM" /> ';
    			 echo ' <input type="submit" name="Annuler" id="Annuler" value="Annuler" />  ';
    			 echo ' </p>';
    			 echo '</fieldset> <br/>';
    			 echo '</form>	';
     }
    Traitement après selection des checkbox
    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
    if (isset($_POST['generer_ram']))
    {
    	//var_dump($_POST['checkbox']);
    	if (isset($_POST['checkbox']))
            { 
    		$checkbox = $_POST['checkbox'];
    		echo '<table><tr>
    		<th>DATE </th>
    		<th>PROJETS / TÂCHES</th>
    		<th>DESCRIPTION</th>
    		<th>ETAT D’AVANCEMENT	</th>
    		<th>RESPONSABLE </th>
    		<th>ETAT </th>
    		</tr>';
    		//recupérer ces valeurs dans un array
                     $tabCheckbox = ($_POST['checkbox']);
                     foreach ($tabCheckbox as $checkbox) 
    		 {
                     $checkbox[] = htmlspecialchars($checkbox);
                     $reponse = $bdd->query("SELECT 
    	            a.id_rah,
    		 a.datejour,
    		 a.projets_taches,
    		 a.description,
    		 a.avancement,
    		 a.entite_responsable,
    		 a.etat_tache
    		 FROM 
    		 rah a 
    		 where a.datejour = '$checkbox' order by a.datejour");
                    $donnees = $reponse->fetch();
    		$i++;
    		echo '<tr>';
    		echo '
    			<td>'. $donnees['datejour'].'</td>
    			<td>'. $donnees['projets_taches'].'</td>
    			<td>'. $donnees['description'].'</td>
    			<td>'. $donnees['avancement'].'</td>
    			<td>'. $donnees['entite_responsable'].'</td>
    			<td>'. $donnees['etat_tache'].'</td>';
    		echo '</tr>';
    		}

    Merci pour la precision sur addslashes() en PDO .

  4. #4
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Enlève le
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    enctype="multipart/form-data"

  5. #5
    Membre régulier
    Homme Profil pro
    Technicien réseau
    Inscrit en
    Janvier 2010
    Messages
    119
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations professionnelles :
    Activité : Technicien réseau
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Janvier 2010
    Messages : 119
    Points : 77
    Points
    77
    Par défaut
    Après avoir supprimé
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    enctype="multipart/form-data"
    il ne m'affiche toujours rien lorsque je clique sur
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    echo '<input type="submit" name="generer_ram" id="generer_ram" value="RAM" /> ';
    après l'affichage du tableau.

Discussions similaires

  1. Réponses: 6
    Dernier message: 12/01/2007, 16h48
  2. Réponses: 2
    Dernier message: 22/05/2006, 16h44
  3. Réponses: 2
    Dernier message: 21/05/2006, 14h02
  4. Récupération des informations memoire
    Par xxiemeciel dans le forum Windows
    Réponses: 2
    Dernier message: 12/08/2005, 16h43
  5. Réponses: 9
    Dernier message: 17/08/2004, 16h16

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