par
antitrust56 » 15 mars 2009, 02:00
En affichant mes requêtes dans mon navigateur, je m'aperçois que des champs vides sont insérés dans ma base dû certainement à la fonction explode.
Exemple en saisissant 3 entrées :
Code : Tout sélectionner
INSERT INTO description(id_description, texte1_description, texte2_description, texte3_description, texte4_description, id_site) Values('','Titre 1 ','Description 1 ','Mots-clés 1 ','URL 1 ','33')
INSERT INTO description(id_description, texte1_description, texte2_description, texte3_description, texte4_description, id_site) Values('','','','','','33')
INSERT INTO description(id_description, texte1_description, texte2_description, texte3_description, texte4_description, id_site) Values('','Titre 2 ','Description 2 ','Mots-clés 2 ','URL 2 ','33')
INSERT INTO description(id_description, texte1_description, texte2_description, texte3_description, texte4_description, id_site) Values('','','','','','33')
INSERT INTO description(id_description, texte1_description, texte2_description, texte3_description, texte4_description, id_site) Values('','Titre 3','Description 3','Mots-clés 3','URL 3','33')
J'ai essayé count() mais le problème, c'est qu'il me retourne le nombre d'entrée saisit dans le textarea + le nombre de champs vide (J'ai essayer aussi $champ_form1[0] mais sans succès.
Pour le foreach, celà me retourne l'erreur "Invalid argument supplied for foreach()"
Code : Tout sélectionner
<?php
if (isset($_GET['valid'])) {
$champ_form1 = $_POST['champ1'];
$champ_form2 = $_POST['champ2'];
$champ_form3 = $_POST['champ3'];
$champ_form4 = $_POST['champ4'];
$champ_formulaire1 = explode("\n",$champ_form1);
$champ_formulaire2 = explode("\n",$champ_form2);
$champ_formulaire3 = explode("\n",$champ_form3);
$champ_formulaire4 = explode("\n",$champ_form4);
$j = count($champ_formulaire1);
foreach ($j as $i) {
$req="INSERT INTO description(id_description, texte1_description, texte2_description, texte3_description, texte4_description, id_site) Values('','$champ_formulaire1[$i]','$champ_formulaire2[$i]','$champ_formulaire3[$i]','$champ_formulaire4[$i]','$site')";
echo ($req)."<br>";
$i++;
}
}
?>
José
En affichant mes requêtes dans mon navigateur, je m'aperçois que des champs vides sont insérés dans ma base dû certainement à la fonction explode.
Exemple en saisissant 3 entrées :
[code]INSERT INTO description(id_description, texte1_description, texte2_description, texte3_description, texte4_description, id_site) Values('','Titre 1 ','Description 1 ','Mots-clés 1 ','URL 1 ','33')
INSERT INTO description(id_description, texte1_description, texte2_description, texte3_description, texte4_description, id_site) Values('','','','','','33')
INSERT INTO description(id_description, texte1_description, texte2_description, texte3_description, texte4_description, id_site) Values('','Titre 2 ','Description 2 ','Mots-clés 2 ','URL 2 ','33')
INSERT INTO description(id_description, texte1_description, texte2_description, texte3_description, texte4_description, id_site) Values('','','','','','33')
INSERT INTO description(id_description, texte1_description, texte2_description, texte3_description, texte4_description, id_site) Values('','Titre 3','Description 3','Mots-clés 3','URL 3','33')
[/code]
J'ai essayé count() mais le problème, c'est qu'il me retourne le nombre d'entrée saisit dans le textarea + le nombre de champs vide (J'ai essayer aussi $champ_form1[0] mais sans succès.
Pour le foreach, celà me retourne l'erreur "Invalid argument supplied for foreach()"
[code]<?php
if (isset($_GET['valid'])) {
$champ_form1 = $_POST['champ1'];
$champ_form2 = $_POST['champ2'];
$champ_form3 = $_POST['champ3'];
$champ_form4 = $_POST['champ4'];
$champ_formulaire1 = explode("\n",$champ_form1);
$champ_formulaire2 = explode("\n",$champ_form2);
$champ_formulaire3 = explode("\n",$champ_form3);
$champ_formulaire4 = explode("\n",$champ_form4);
$j = count($champ_formulaire1);
foreach ($j as $i) {
$req="INSERT INTO description(id_description, texte1_description, texte2_description, texte3_description, texte4_description, id_site) Values('','$champ_formulaire1[$i]','$champ_formulaire2[$i]','$champ_formulaire3[$i]','$champ_formulaire4[$i]','$site')";
echo ($req)."<br>";
$i++;
}
}
?>[/code]
José