j'ai un probleme concernant la récupération du valeur input dans une boucle.
<?php mysql_connect("localhost","root","123") or die(mysql_error()); mysql_select_db("basepfe")or die('Pas de Base de donn\351'); // Présentation de la requête avec des retours à la ligne // c'est plus lisible... $sql="SELECT t.num ,t.nomE ,t.prenom FROM etudiant AS t ,filiere AS f WHERE f.nomF = '$e' AND f.annee = '$d'"; $t=mysql_query($sql); while($result=mysql_fetch_array($t)){ $num = $result['num']; $nom = $result['nomE']; $prenom = $result['prenom']; echo "<tr> </tr> <th><".$num."</th> <th>".$nom."</th> <th>".$prenom."</th>"; // A quoi correspond ta variable : $nbResult // Où l'as tu initialisée dans ton code ? for($i=0;$i<$nbResult;$i++){ echo'<th><input type="text" name="'.$i.'" value=""/></th>'; } echo "</tr>"; // .... // Fin du While } ?>
mysql_connect("localhost","root","123") or die(mysql_error()); mysql_select_db("basepfe")or die('Pas de Base de donn\351'); $sql1= ("(SELECT t.TYPE FROM TYPE AS t, assocts AS l, smodule AS s, filiere AS f WHERE t.idT = l.idT AND l.idS = s.idS AND nomF = '$e' AND annee ='$d' AND nomS ='$c')"); $u=mysql_query($sql1); $nbResult = mysql_num_rows($u); while($resu=mysql_fetch_array($u)) { $type1 = $resu['TYPE']; echo "<th>".$type1."</th>"; } ?> <?php mysql_connect("localhost","root","123") or die(mysql_error()); mysql_select_db("basepfe")or die('Pas de Base de donn\351'); $sql=("SELECT t.num, t.nomE, t.prenom FROM etudiant AS t, filiere AS f WHERE f.nomF = '$e' AND f.annee = '$d'"); $t=mysql_query($sql); while($result=mysql_fetch_array($t)) { $num = $result['num']; $nom = $result['nomE']; $prenom = $result['prenom']; //echo"<tr><th><input type='text' name='note2' value=''/></th></tr>" ?> </tr> <th><?php echo $num; ?></th> <th><?php echo $nom; ?></th> <th><?php echo $prenom; ?></th> <?php //boucle qui crée les input selon les types d'évaluations créé par le prof for($i=0;$i<$nbResult;$i++){ echo'<th><input type="text" name='.$i.' value=""/></th>'; } ?> </tr> <?php } echo "<script> location.reload(); <script>";?>
j'éspére que c'est clair,NON...
c'est ca mon probleme j'ai pas arrivé à écrire une req qui fait la récuperation des valeurs entrés dans une boucle... ce qui signifie ??
mysql_connect("localhost","root","123") or die(mysql_error()); mysql_select_db("basepfe")or die('Pas de Base de donn\351');
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question$k="insert into note values ('','$t')"; $t=mysql_query($k); $k=mysql_insert_id(); $c="insert into associer values('$k','num','idT','idS')"; $h=mysql_query($c);
<form method="POST"> <table border="2" id="tab"> <tr><th colspan='7'>Analyse</th></tr> <tr class="ligne"> <th>Num</th> <th>Nom</th> <th>Prenom</th> <?php mysql_connect("localhost","root","123") or die(mysql_error()); mysql_select_db("basepfe")or die('Pas de Base de donn\351'); $sql1= ("(SELECT t.TYPE FROM TYPE AS t, assocts AS l, smodule AS s, filiere AS f WHERE t.idT = l.idT AND l.idS = s.idS AND nomF = '$e' AND annee ='$d' AND nomS ='$c')"); $u=mysql_query($sql1); $nbResult = mysql_num_rows($u); while($resu=mysql_fetch_array($u)) { $type1 = $resu['TYPE']; echo "<th>".$type1."</th>"; } ?> <?php mysql_connect("localhost","root","123") or die(mysql_error()); mysql_select_db("basepfe")or die('Pas de Base de donn\351'); $sql=("SELECT t.num, t.nomE, t.prenom FROM etudiant AS t, filiere AS f WHERE f.nomF = '$e' AND f.annee = '$d'"); $t=mysql_query($sql); while($result=mysql_fetch_array($t)) { $num = $result['num']; $nom = $result['nomE']; $prenom = $result['prenom']; //echo"<tr><th><input type='text' name='note2' value=''/></th></tr>" ?> </tr> <th><?php echo $num; ?></th> <th><?php echo $nom; ?></th> <th><?php echo $prenom; ?></th> <?php //echo $nbResult; for($i=0;$i<$nbResult;$i++){ echo'<th><input type="text" name='.$i.' value=""/></th>'; } ?> </tr> <?php } echo "<script> location.reload(); <script>";?> </table> <input type="submit" id="Button2" name="enre" value="Enregistrer" > </form>
mysql_connect("localhost","root","123") or die(mysql_error()); mysql_select_db("basepfe")or die('Pas de Base de donn\351'); $sql1= ("(SELECT t.TYPE, t.idT,s.idS FROM TYPE AS t, assocts AS l, smodule AS s, filiere AS f WHERE t.idT = l.idT AND l.idS = s.idS AND nomF = 'Genie informatique' AND annee ='2eme' AND nomS ='analyse')"); $u=mysql_query($sql1); $nbResult = mysql_num_rows($u); while($row = mysql_fetch_array($u)) { $type1 = $row['TYPE']; $idT = $row['idT']; $idS = $row['idS']; echo "<th>".$type1."</th></br>"; ; } echo'</tr>'; for($i=0;$i<$nbResult;$i++){ echo "<th><input type='text' name='ligne".$i."' id='ligne".$i."'/></th>"; }
mysql_connect("localhost","root","123") or die(mysql_error()); mysql_select_db("basepfe")or die('Pas de Base de donn\351'); $num=$_SESSION['a']; $m=$_POST['r']; $a=$_POST["'$i'ligne"]; if(isset($m)){ $sqll="insert into test VALUES('','$idT','$idS','$num','$a')"; echo $sqll; mysql_query($sqll); }
Echo "<br> Variables POST : <br>"; print_r($_POST); Echo "<br> Variables SESSION: <br>"; print_r($_SESSION);
session_start()au début de tes pages.
ce que j'ai remarqué,il récupere les variables post mais au niveau de l'insertion ca marche pas
$a=$_POST["'$i'ligne"];
et pour les variables session il ne récupere rien.Ben si...; la variable $_SESSION['login'] contient bien : "mounir"....
for($i=0;$i<$nbResult;$i++){ echo "<th><input type='text' name='ligne".$i."' id='ligne".$i."'/></th>"; }
si il est là:
$a=$_POST["ligne'$i'"]; c'est comme ca on recupére name?Oui ce serait déjà mieux
$a=$_POST['ligne0'];
<?php if(isset($_POST['toto'])){ // Affichage des variables POST echo "<br> Variables POST : "; print_r($_POST); echo "<br>"; // Récupération des Inputs : foreach($_POST as $name=>$valeur){ if(substr( $name, 0, 9 )=="monInput_"){ // On sépare le nom de l'input pour récupérer sa valeur de $i $arrNom = explode("_",$name); $i =$arrNom[1]; // on affiche la valeur et le numéro : echo "Nom => ".$name." i =>".$i." Valeur =>".$valeur."<br>"; } } } ?> <html> <head><title>TEST</title></head> <body> <form name="test" method="post" action=""> <?php for($i=0;$i<10;$i++){ echo "<br> Input N° ".$i." <input type='text' name='monInput_".$i."' id='imp_".$i."' value=''> "; } ?> <input type="submit" name="toto" value="valider"> </form> </body> </html>
<form method='POST'> <table border="2" id="tab"> <tr><th colspan='7'>Analyse</th></tr> <tr class="ligne"> <th>Num</th> <th>Nom</th> <th>Prenom</th> <?php mysql_connect("localhost","root","123") or die(mysql_error()); mysql_select_db("basepfe")or die('Pas de Base de donn\351'); $sql1= ("(SELECT t.TYPE FROM TYPE AS t, assocts AS l, smodule AS s, filiere AS f WHERE t.idT = l.idT AND l.idS = s.idS AND nomF = '$e' AND annee ='$d' AND nomS ='$c')"); $s=mysql_query($sql1); $nbResult = mysql_num_rows($s); while($resu=mysql_fetch_array($s)) { $type1 = $resu['TYPE']; echo "<th>".$type1."</th>"; } ?> <?php mysql_connect("localhost","root","123") or die(mysql_error()); mysql_select_db("basepfe")or die('Pas de Base de donn\351'); $sql= ("SELECT t.num, t.nomE, t.prenom FROM etudiant AS t, filiere AS f WHERE f.nomF = '$e' AND f.annee = '$d' LIMIT 5 "); $m=mysql_query($sql); while($result=mysql_fetch_array($m)) { $num = $result['num']; $nom = $result['nomE']; $prenom = $result['prenom']; //echo"<tr><th><input type='text' name='note2' value=''/></th></tr>" ?> </tr> <th><?php echo $num; ?></th> <th><?php echo $nom; ?></th> <th><?php echo $prenom; ?></th> <?php for($i=0;$i<$nbResult;$i++){ echo "<th><input type='text' name='monInput_".$i."' id='imp_".$i."'/></th>"; } ?> </tr> <?php } //echo "<script> location.reload(); <script>";?> </table> <input type="submit" name="r" value="Inserer"/> </form> </body> <?php mysql_connect("localhost","root","123") or die(mysql_error()); mysql_select_db("basepfe")or die('Pas de Base de donn\351'); $m=$_POST['r']; $a=$_POST["monInput_'$i'"]; if(isset($_POST['r'])){ // Affichage des variables POST echo "<br> Variables POST : "; print_r($_POST); echo "<br>"; // Récupération des Inputs : foreach($_POST as $name=>$valeur){ if(substr( $name, 0, 9 )=="monInput_"){ // On sépare le nom de l'input pour récupérer sa valeur de $i $arrNom = explode("_",$name); $i =$arrNom[1]; // on affiche la valeur et le numéro : echo "Nom => ".$name." i =>".$i." Valeur =>".$valeur."<br>"; } } } ?>
// Faire : $m=isset($_POST['r'])?$_POST['r']:''; // Au lieu de : $m=$_POST['r'];
<?php //------------------------------------------------------------- // Connexion à la BDD (que tu pourrais mettre dans un fichier à part au passage ! //------------------------------------------------------------- mysql_connect("localhost","root","123") or die(mysql_error()); mysql_select_db("basepfe")or die('Pas de Base de donn\351'); //------------------------------------------------------------- // Traitement du submit : //------------------------------------------------------------- if(isset($_POST['r'])){ // Affichage des variables POST echo "<br> Variables POST : "; print_r($_POST); echo "<br>"; // Récupération des Inputs : foreach($_POST as $name=>$valeur){ if(substr( $name, 0, 9 )=="monInput_"){ // On sépare le nom de l'input pour récupérer sa valeur de $i $arrNom = explode("_",$name); $i =$arrNom[1]; // on affiche la valeur et le numéro : echo "Nom => ".$name." i =>".$i." Valeur =>".$valeur."<br>"; } } } //------------------------------------------------------------- // Création du formulaire sur la page //------------------------------------------------------------- ?> <form method='POST'> <table border="2" id="tab"> <tr> <th colspan='7'>Analyse</th> </tr> <tr class="ligne"> <th>Num</th> <th>Nom</th> <th>Prenom</th> <?php $sql1="SELECT t.TYPE FROM TYPE AS t , assocts AS l , smodule AS s , filiere AS f WHERE t.idT = l.idT AND l.idS = s.idS AND nomF = '$e' AND annee ='$d' AND nomS ='$c'"; $s=mysql_query($sql1); // etc... le reste de ton code ... //.... ?>
<?php mysql_connect("localhost","root","123") or die(mysql_error()); mysql_select_db("basepfe")or die('Pas de Base de donn\351'); // Traitement du submit : //------------------------------------------------------------- $m=isset($_POST['r'])?$_POST['r']:''; $a=isset($_POST["monInput_'$i'"])?$_POST["monInput_'$i'"]:''; if(isset($_POST['r'])){ // Affichage des variables POST echo "<br> Variables POST : "; print_r($_POST); echo "<br>"; // Récupération des Inputs : foreach($_POST as $name=>$valeur){ if(substr( $name, 0, 9 )=="monInput_"){ // On sépare le nom de l'input pour récupérer sa valeur de $i $arrNom = explode("_",$name); $i =$arrNom[1]; // on affiche la valeur et le numéro : echo "Nom => ".$name." i =>".$i." Valeur =>".$valeur."<br>"; } } } //------------------------------------------------------------- // Création du formulaire sur la page //------------------------------------------------------------- ?> <form method='POST'> <table border="2" id="tab"> <tr><th colspan='7'>Analyse</th></tr> <tr class="ligne"> <th>Num</th> <th>Nom</th> <th>Prenom</th> <?php //------------------------------------------------------------ //affichage des types d'évaluations crée par un prof $sql1="SELECT t.TYPE FROM TYPE AS t , assocts AS l , smodule AS s , filiere AS f WHERE t.idT = l.idT AND l.idS = s.idS AND nomF = '$e' AND annee ='$d' AND nomS ='$c'"; $u=mysql_query($sql1); $nbResult = mysql_num_rows($u); while($resu=mysql_fetch_array($u)) { $type1 = $resu['TYPE']; echo "<th>".$type1."</th>"; } //------------------------------------------------------------ //affichage des étudiants $sql=("SELECT t.num, t.nomE, t.prenom FROM etudiant AS t ,filiere AS f WHERE f.nomF = '$e' AND f.annee = '$d' LIMIT 5"); $t=mysql_query($sql); while($result=mysql_fetch_array($t)) { $num = $result['num']; $nom = $result['nomE']; $prenom = $result['prenom']; ?> </tr> <tr> <th><?php echo $num; ?></th> <th><?php echo $nom; ?></th> <th><?php echo $prenom; ?></th> <?php for($i=0;$i<$nbResult;$i++){ echo "<th><input type='text' name='monInput_".$i."' id='imp_".$i."'/></th>"; } ?> </tr> <?php } ?> </table> <input type="submit" name="re" value="Enregistrer" > </form>
$a=isset($_POST["monInput_'$i'"])?$_POST["monInput_'$i'"]:'';
?> </tr> <tr> <th><?php echo $num; ?></th> <th><?php echo $nom; ?></th> <th><?php echo $prenom; ?></th> <?php
echo "</tr> <tr> <th>".$num."</th> <th>".$nom."</th> <th>".$prenom."</th>";
?> </tr> <?php } ?>
echo "</tr>"; } ?>
<?php mysql_connect("localhost","root","123") or die(mysql_error()); mysql_select_db("basepfe")or die('Pas de Base de donn\351'); // Traitement du submit : //------------------------------------------------------------- $m=isset($_POST['r'])?$_POST['r']:''; if(isset($_POST['r'])){ // Affichage des variables POST echo "<br> Variables POST : "; print_r($_POST); echo "<br>"; // Récupération des Inputs : foreach($_POST as $name=>$valeur){ if(substr( $name, 0, 9 )=="monInput_"){ // On sépare le nom de l'input pour récupérer sa valeur de $i $arrNom = explode("_",$name); $i =$arrNom[1]; // on affiche la valeur et le numéro : echo "Nom => ".$name." i =>".$i." Valeur =>".$valeur."<br>"; } } } //------------------------------------------------------------- // Création du formulaire sur la page //------------------------------------------------------------- ?> <form method='POST'> <table border="2" id="tab"> <tr><th colspan='7'>Analyse</th></tr> <tr class="ligne"> <th>Num</th> <th>Nom</th> <th>Prenom</th> <?php //------------------------------------------------------------ //affichage des types d'évaluations crée par un prof $sql1="SELECT t.TYPE FROM TYPE AS t , assocts AS l , smodule AS s , filiere AS f WHERE t.idT = l.idT AND l.idS = s.idS AND nomF = '$e' AND annee ='$d' AND nomS ='$c'"; $u=mysql_query($sql1); $nbResult = mysql_num_rows($u); while($resu=mysql_fetch_array($u)) { $type1 = $resu['TYPE']; echo "<th>".$type1."</th>"; } //------------------------------------------------------------ //affichage des étudiants $sql=("SELECT t.num, t.nomE, t.prenom FROM etudiant AS t ,filiere AS f WHERE f.nomF = '$e' AND f.annee = '$d' LIMIT 5"); $t=mysql_query($sql); while($result=mysql_fetch_array($t)) { $num = $result['num']; $nom = $result['nomE']; $prenom = $result['prenom']; echo "</tr> <tr> <th>".$num."</th> <th>".$nom."</th> <th>".$prenom."</th>"; for($i=0;$i<$nbResult;$i++){ echo "<th><input type='text' name='monInput_".$i."' id='imp_".$i."'/></th>"; } echo'</tr>'; } ?> </table> <input type="submit" name="r" value="Enregistrer" > </form>
<?php mysql_connect("localhost","root","123") or die(mysql_error()); mysql_select_db("basepfe")or die('Pas de Base de donn\351'); // Traitement du submit : //------------------------------------------------------------- $m=isset($_POST['r'])?$_POST['r']:''; if(isset($_POST['r'])){ // Affichage des variables POST echo "<br> Variables POST : "; print_r($_POST); echo "<br>"; // Récupération des Inputs : foreach($_POST as $name=>$valeur){ if(substr( $name, 0, 9 )=="monInput_"){ // On sépare le nom de l'input pour récupérer sa valeur de $i $arrNom = explode("_",$name); $N =$arrNom[1]; $i =$arrNom[2]; // on affiche la valeur et le numéro : echo "Nom => ".$name." Num =>".$N." i =>".$i." Valeur =>".$valeur."<br>"; } } } //------------------------------------------------------------- // Création du formulaire sur la page //------------------------------------------------------------- ?> <form method='POST'> <table border="2" id="tab"> <tr><th colspan='7'>Analyse</th></tr> <tr class="ligne"> <th>Num</th> <th>Nom</th> <th>Prenom</th> <?php //------------------------------------------------------------ //affichage des types d'évaluations crée par un prof $sql1="SELECT t.TYPE FROM TYPE AS t , assocts AS l , smodule AS s , filiere AS f WHERE t.idT = l.idT AND l.idS = s.idS AND nomF = '$e' AND annee ='$d' AND nomS ='$c'"; $u=mysql_query($sql1); $nbResult = mysql_num_rows($u); while($resu=mysql_fetch_array($u)) { $type1 = $resu['TYPE']; echo "<th>".$type1."</th>"; } //------------------------------------------------------------ //affichage des étudiants $sql=("SELECT t.num, t.nomE, t.prenom FROM etudiant AS t ,filiere AS f WHERE f.nomF = '$e' AND f.annee = '$d' LIMIT 5"); $t=mysql_query($sql); while($result=mysql_fetch_array($t)) { $num = $result['num']; $nom = $result['nomE']; $prenom = $result['prenom']; echo "</tr> <tr> <th>".$num."</th> <th>".$nom."</th> <th>".$prenom."</th>"; for($i=0;$i<$nbResult;$i++){ // Chaque input appartient à UNE personne.. et à UN type. // num étant égale au Numéro de la personne // i égale au numéro du TYPE echo "<th><input type='text' name='monInput_".$num."_".$i."' id='imp_".$i."'/></th>"; } echo'</tr>'; } ?> </table> <input type="submit" name="r" value="Enregistrer" > </form>
<br> Variables POST : Array ( [monInput_1_0] => 1 [monInput_2_0] => 2 [monInput_3_0] => 3 [monInput_4_0] => 4 [monInput_5_0] => 5 [r] => Enregistrer ) <br>Nom => monInput_1_0 Num =>1 i =>0 Valeur =>1<br>Nom => monInput_2_0 Num =>2 i =>0 Valeur =>2<br>Nom => monInput_3_0 Num =>3 i =>0 Valeur =>3<br>Nom => monInput_4_0 Num =>4 i =>0 Valeur =>4<br>Nom => monInput_5_0 Num =>5 i =>0 Valeur =>5<br><form method='POST'> <table border="2" id="tab"> <tr><th colspan='7'>Analyse</th></tr> <tr class="ligne"> <th>Num</th> <th>Nom</th> <th>Prenom</th> <th>Projet</th></tr> <tr> <th>1</th> <th>AABID</th> <th>MOHAMED AMINE</th><th><input type='text' name='monInput_1_0' id='imp_0'/></th></tr></tr> <tr> <th>2</th> <th>ABI </th> <th>ISMA3IL </th><th><input type='text' name='monInput_2_0' id='imp_0'/></th></tr></tr> <tr> <th>3</th> <th>ABOUHAFS</th> <th>ZINEB</th><th><input type='text' name='monInput_3_0' id='imp_0'/></th></tr></tr> <tr> <th>4</th> <th>AZAM</th> <th>OMAR ESSAID</th><th><input type='text' name='monInput_4_0' id='imp_0'/></th></tr></tr> <tr> <th>5</th> <th>BELASSAL</th> <th>SALMA</th><th><input type='text' name='monInput_5_0' id='imp_0'/></th></tr> </table> <input type="submit" name="r" value="Enregistrer" > </form>
$m=isset($_POST['r'])?$_POST['r']:''; $a=isset($_POST["monInput_'$i'"])?$_POST["monInput_'$i'"]:''; $idT=$_SESSION['k']; $num=$_SESSION['h']; if(isset($_POST['r'])){ // Affichage des variables POST echo "<br> Variables POST : "; print_r($_POST); echo "<br>"; // Récupération des Inputs : foreach($_POST as $name=>$valeur){ if(substr( $name, 0, 9 )=="monInput_"){ // On sépare le nom de l'input pour récupérer sa valeur de $i $arrNom = explode("_",$name); $N =$arrNom[1]; $i =$arrNom[2]; // on affiche la valeur et le numéro : echo "Nom => ".$name." Num =>".$N." i =>".$i." Valeur =>".$valeur."<br>"; $sql="insert into test values('','$idT','15','$num','$valeur')"; mysql_query($sql); echo $sql;lors de l'affichage la variable $num recupérer est juste celui du derniere étudiant,est ce que je dois refaire la boucle du while sur les étudiants à l'interieure du boucle foreach?
30 mai 2014 à 20:22
mais il m'affiche un erreur:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in C:\AppServ\www\pfe\test1\type.php on line 72
30 mai 2014 à 20:32