j'ai le même problème pour insèrer plusieurs ligne de données.
J'ai un formulaire ou je peux choisir le nombre de fiche a insèrer dans la base je choisi,j'envoi si il y en a qu'un ça l'ajoute,si il y en a plusieurs ça m'emmène sur cette page
<?php
//paramètres de la base
$serveur="localhost";
$util="root";
$mpasse="";
$base="stocks";
// connexion au serveur Mysql
$lien=mysql_connect($serveur,$util,$mpasse);
// connexion à la base de données
mysql_select_db($base);
// réccupération des données du formulaire
$nb_fiches=strip_tags($_POST['nb_fiches']);
$jour=strip_tags($_POST['jour']);
$commande=strip_tags($_POST['commande']);
$produit=strip_tags($_POST['produit']);
$marque=strip_tags($_POST['marque']);
$designation=strip_tags($_POST['designation']);
$sequence=strip_tags($_POST['sequence']);
$etat=strip_tags($_POST['etat']);
$commentaire=strip_tags($_POST['commentaire']);
$serie=strip_tags($_POST['serie']);
$date=strip_tags($_POST['date']);
$affectation=strip_tags($_POST['affectation']);
$nom=strip_tags($_POST['nom']);
$dt= date("d/m/Y");
$dt2= date("Y");
if ($nb_fiches=="")
{
// Ajout d'une nouvelle fiche à la table user
mysql_query("INSERT INTO Pcs VALUES(NULL,'$jour','$commande','$produit','$marque','$designation','$sequence','$etat','$commentaire','$serie','$date','$affectation','$nom')");
echo "<meta http-equiv='refresh' content='1; url=index.php'>";
mysql_close(); // Déconnexion de MySQL
}
else {
echo "
<font color='white' size='5'><center><b>Ajouterunefiche</b></center></font><br /><br />";
echo "<table border='1' bordercolor='yellow' width='4050'>
<tr>
<td width='50'><font color ='white'>n°</font></td>
<td width='300'><font color ='white'>jour</font></td>
<td width='300'><font color ='white'>commande</font></td>
<td width='300'><font color ='white'>produit</font></td>
<td width='300'><font color ='white'>marque</font></td>
<td width='300'><font color ='white'>designation</font></td>
<td width='300'><font color ='white'>sequence</font></td>
<td width='300'><font color ='white'>etat</font></td>
<td width='300'><font color ='white'>commentaire</font></td>
<td width='300'><font color ='white'>serie</font></td>
<td width='300'><font color ='white'>date</font></td>
<td width='300'><font color ='white'>affectation</font></td>
<td width='300'><font color ='white'>nom</font></td>
</tr>
</table>";
for($i=1;$i<=$nb_fiches;$i++)
{
$nb=$i;
$sequence=$nb_fiches;
echo " <form action='ajout3.php' name='nb_fiches[]' method='post'>";
echo " <table width='4050' align='center' border='1' bordercolor='yellow'>
<tr>
<td width='300'><font color ='white'>$nb</font></td>
<td width='300'><input type='text' name='jour[]' value='$jour' size='50' /></td>
<td width='300'><input type='text' name='commande[]' value='$commande' size='50' /></td>
<td width='300'><input type='text' name='produit[]' value='$produit' size='50' /></td>
<td width='300'><input type='text' name='marque[]' value='$marque' value=size='50' /></td>
<td width='300'><input type='text' name='designation[]' value='$designation' size='50' /></td>
<td width='300'><input type='text' name='sequence[]' value='$nb/$sequence' size='50' /></td>
<td width='300'><input type='text' name='etat[]' value='$etat' size='50' /></td>
<td width='300'><input type='text' name='commentaire[]' value='$commentaire' size='50' /></td>
<td width='300'><input type='text' name='serie[]' value='$serie' size='50' /></td>
<td width='300'><input type='text' name='date[]' value='$date' size='50' /></td>
<td width='300'><input type='text' name='affectation[]' value='$affectaion' size='50' /></td>
<td width='300'><input type='text' name='nom[]' value='$nom' size='50' /></td>
</tr>
</table>";
}
echo "<input type='submit' name='ajouter' value='ajouter le contact' /></form>
<font size='4'><a href='index.php'><center><b>Retour</center></b></a></font><br />";
} ?>
Après j'envoie mes données a insèrer et ça m'envoie sur mon fichier qui traite l'insertion
<?php
//paramètres de la base
$serveur="localhost";
$util="root";
$mpasse="";
$base="stocks";
// connexion au serveur Mysql
$lien=mysql_connect($serveur,$util,$mpasse);
// connexion à la base de données
mysql_select_db($base);
$nb_fiches=strip_tags($_POST['nb_fiches[$i]']);
// Traitement
for ($i=0;$i>$nb_fiches;$i++)
{ // boucle de traitement
$jour=strip_tags($_POST['jour[$i]']);
$commande=strip_tags($_POST['commande[$i]']);
$produit=strip_tags($_POST['produit[$i]']);
$marque=strip_tags($_POST['marque[$i]']);
$designation=strip_tags($_POST['designation[$i]']);
$sequence=strip_tags($_POST['sequence[$i]']);
$etat=strip_tags($_POST['etat[$i]']);
$commentaire=strip_tags($_POST['commentaire[$i]']);
$serie=strip_tags($_POST['serie[$i]']);
$date=strip_tags($_POST['date[$i]']);
$affectation=strip_tags($_POST['affectation[$i]']);
$nom=strip_tags($_POST['nom[$i]']);
mysql_query("INSERT INTO Pcs VALUES(NULL,'$jour','$commande','$produit','$marque','$designation','$sequence','$etat','$commentaire','$serie','$date','$affectation','$nom')");
echo "<meta http-equiv='refresh' content='1; url=index.php'>";
}
mysql_close(); // Déconnexion de MySQL
echo "<meta http-equiv='refresh' content='1; url=index.php'>"; // redirection vers l'index
?>
Je n'arrive pas a terminer ce fichier je sais qu'il faut mettre des $i dans les $_POST['champ'] mais je ne sais pas comment.