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 :

Invalid argument supplied for foreach()


Sujet :

Langage PHP

  1. #1
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2016
    Messages
    275
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2016
    Messages : 275
    Points : 76
    Points
    76
    Par défaut Invalid argument supplied for foreach()
    bonsoir, j'ai un petit soucis avec mon xml, il m'affiche cette erreur : Notice: Undefined index: technologie in C:\wamp64\www\Formulaire\cible.php ainsi que Warning: Invalid argument supplied for foreach() in C:\wamp64\www\Formulaire\cible.php
    suite a un ajout de ligne le problème c'est manifesté voici le code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    		<?php
    		$listetechnologie = "";
    		foreach ($_POST['technologie'] as $value) {
    			$listetechnologie = $listetechnologie.$value.", " ;
    		}
    merci

  2. #2
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Points : 15 059
    Points
    15 059
    Par défaut
    Bonjour,

    $_POST['technologie'] doit exister et doit être un tableau.
    Peut-on voir ton formulaire?

    A+.

  3. #3
    Membre éclairé Avatar de Geoffrey74
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2007
    Messages
    515
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2007
    Messages : 515
    Points : 760
    Points
    760
    Par défaut
    Petit astuce, pour éviter une boucle foreach qui réalise cette opération, tu as la fonction join

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    join(', ', $_POST['technologie']);

  4. #4
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2016
    Messages
    275
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2016
    Messages : 275
    Points : 76
    Points
    76
    Par défaut
    voici mon code en entier et j'ai essayé le code join mais sa ne fonctionne pas
    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
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    <html>
    <body>
    		<?php
    		$today= date("d.m.y");
    		$Titre=$_POST['Titre'] ;
    		$Sujet=$_POST['Sujet'] ;
    		$niveau=$_POST['niveau'];
    		$listetechnologie = "";
    		$listemetier = "";
    		$listetheme = "";
    		$coordonnees = "";
    		//var_dump($_POST['technologie'] );
    		join(', ', $_POST['technologie']) {
    			$listetechnologie = $listetechnologie.$value.", " ;
    		}
     
     
    		foreach ($_POST['metier'] as $value) {
    			$listemetier = $listemetier.$value.", ";
    		}
    	foreach ($_POST['theme'] as $value) {
    			$listetheme = $listetheme.$value.", ";
    		}		
     
    		$Nom=$_POST['Nom'];
    		$Prenom=$_POST['Prenom'];
    		$Mail=$_POST['Mail'];
    		$Twitter=$_POST['Twitter'];
    		$Facebook=$_POST['Facebook'];
     
    		 $coordonnees = $coordonnees.$Nom."<br>".$Prenom."<br>".$Mail."<br>".$Twitter."<br>".$Facebook;
     
     
    		$Entreprise=$_POST['Entreprise'];
    		$ouinon=$_POST['ouinon'];
    		?>
     
     
    <table border = 2>
    	     <tr> 
    		 <th>Titre </th> 
    		<th> <?= $Titre; ?></th>
    		</tr>
    		 <tr> 
     
    		<th> Sujet</th>
    		<th><?= $Sujet;?> </th>
    		</tr>
    	 <tr> 
     
    		<th> niveau</th>
    		<th><?= $niveau;?> </th>
    		</tr>
    		<tr>
    			<th>Technologie</th>
    		<th><?= $listetechnologie;?> </th>
    		</tr>
    		<tr>
    			<th> metier</th>
    		<th><?= $listemetier;?> </th>
    		</tr>
    		<tr>
    			<th> theme</th>
    		<th><?= $listetheme;?> </th>
    		</tr>
    		<tr>
    			<th> Coordonées</th>
    		<th><?= $coordonnees;?> </th>
    		</tr>
    		<tr>
    			<th> Entreprise</th>
    		<th><?= $Entreprise."<br>".$ouinon;?> </th>
    		</tr>
     
    		 </table>
    		0 <?php
     
                   // 1st param takes version and 2nd param takes encoding;
                     $dom = new DomDocument("1.0", "ISO-8859-1");
     
     
                $conf =  $dom->createElement('Conference');
     
     
     
     
                 // now, we add $toElem as a child of $noteElem
                 $conf->appendChild( $dom->createElement('Titre', $Titre) );
                 $conf->appendChild( $dom->createElement('niveau', $niveau) );
                 $conf->appendChild( $dom->createElement('Sujet', $Sujet) );
     
    			 $listetechnologie= $dom->createElement('technologie');
    			 foreach ($_POST['technologie'] as $value) {
    			 $listetechnologie->appendChild( $dom->createElement('technologie', $value) );
    		     }
             	$conf->appendChild( $listetechnologie );
     
             	 $listemetier= $dom->createElement('metier');
             	 foreach ($_POST['metier'] as $value) {
    			 $listemetier->appendChild( $dom->createElement('metier', $value) );
    		     }
    		     	$conf->appendChild( $listemetier );
     
    		     $listetheme= $dom->createElement('theme');
             	 foreach ($_POST['theme'] as $value) {
    			 $listemetier->appendChild( $dom->createElement('theme', $value) );
    		     }
    		     	$conf->appendChild( $listetheme );
     
     
             $conferencier= $dom->createElement('conferencier');
             $conferencier->appendChild( $dom->createElement('nom', $Nom) );
             $conferencier->appendChild( $dom->createElement('prenom', $Prenom) );
             $conferencier->appendChild( $dom->createElement('Mail', $Mail) );
             $conferencier->appendChild( $dom->createElement('Twitter', $Twitter) );
             $conferencier->appendChild( $dom->createElement('Facebook', $Facebook) );
             $conferencier->appendChild( $dom->createElement('Entreprise', $Entreprise) );
             $conferencier->appendChild( $dom->createElement('ouinon', $ouinon) );
    			 $conf->appendChild($conferencier);
    			 $dom->appendChild($conf);
                 $dom->formatOutput = true; // this adds spaces, new lines and makes the XML more readable format. 
     
     
     
     
               $dom->save($today.$Titre.$Mail.".xml"); 
    		echo "Votre formulaire a ete enregistre";
     
    		?>
     
    </body>
    </html>

  5. #5
    Membre éclairé Avatar de Geoffrey74
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2007
    Messages
    515
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2007
    Messages : 515
    Points : 760
    Points
    760
    Par défaut
    Penses à chercher un peu le fonctionnement des fonctions que l'on te donne, tu aurai trouvé la solution immédiatement...

    Tu peux utiliser aussi implode aussi. (http://php.net/manual/fr/function.implode.php)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $listetechnologie = join(', ', $_POST['technologie']);

Discussions similaires

  1. Warning: Invalid argument supplied for foreach()
    Par billyrose dans le forum Langage
    Réponses: 1
    Dernier message: 27/02/2009, 15h36
  2. [Tableaux] Invalid argument supplied for foreach()
    Par kifouillou dans le forum Langage
    Réponses: 10
    Dernier message: 16/05/2008, 16h53
  3. [Tableaux] Invalid argument supplied for foreach
    Par Lionel57 dans le forum Langage
    Réponses: 1
    Dernier message: 20/12/2007, 13h15
  4. Invalid argument supplied for foreach()
    Par Rajhonson dans le forum Langage
    Réponses: 4
    Dernier message: 16/11/2006, 14h31
  5. Réponses: 11
    Dernier message: 19/05/2006, 11h41

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