Bonjour,,
J'ai un tableaux dynamique qui contient des champs de saisie , le problèm c'est que lors de l'insertion dans la base il y a que la derniere ligne qui s'enregistre voila le code :
1.le code de creation du tableau
<form name="enr" method="post" action="enreg_vun.php" >
<table class="dTable">
<thead>
<tr>
<th>Vunérabilité</th>
<th>Menace</th>
<th>Contre Mesure</th>
<th>Priorité</th>
</tr>
</thead>
<tfoot>
<tr>
<th colspan="5"><a href="#" onclick="addLigne(this); return false;">Ajouter une ligne</a></th>
</tr>
</tfoot>
<tbody>
<tr>
<td><input type="text" id="ch1" name="champ1" /></td>
<td><input type="text" id="ch2" name="champ2" /></td>
<td><input type="text" id="ch3" name="champ3" /></td>
<td><input type="text" id="ch4" name="champ4" /></td>
<td><a href="#" onclick="delLigne(this); return false;">Supp</a></td>
</tr>
</tbody>
</table>
<input name="enre" type="submit" value="Enregistrer"/>
</form>
-------------------------------------------------------------
2.code de l'enregistrement dans la base "enreg_vun.php"
<?php
$ch1 = array();
$ch2 = array();
$ch3 = array();
$ch4 = array();
foreach($_POST as $cle=>$value){
if(substr($cle,0,7)=="champ1"){
$ch1[]=$value;
}
if(substr($cle,0,7)=="champ2"){
$ch2[]=$value;
}
if(substr($cle,0,7)=="champ3"){
$ch3[]=$value;
}
if(substr($cle,0,7)=="champ4"){
$ch4[]=$value;
}
}
include("connection.php");
$nb=0;
for ($i=0;$i<sizeof($ch1);$i++)
{
$req="INSERT INTO vunerabi (champ1,champ2,champ3,champ4) VALUES('".$ch1[$i]."','".$ch2[$i]."','".$ch3[$i]."','".$ch4[$i]."');";
$res=mysql_query($req);
$nb++;
}
echo "<HTML><BODY>".$nb." enregistrements ont été faits dans la base !</HTML></BODY>";
?>
il me donne " 1 enregistrements ont été faits dans la base !
Merci