Enregistrement de tableau avec Id input dans MySQL

Résolu/Fermé
Sinistrus Messages postés 1017 Date d'inscription mercredi 12 décembre 2007 Statut Membre Dernière intervention 6 juin 2023 - 5 juil. 2017 à 13:35
Sinistrus Messages postés 1017 Date d'inscription mercredi 12 décembre 2007 Statut Membre Dernière intervention 6 juin 2023 - 7 juil. 2017 à 21:28
Bonjour à tous !

Voilà, je suis un peu bloquer sur un code et souhaiterais que vous m'aidez.

J'ai une page qui génère un bon de commande dont les input ont des id incrément +i
Je dois récupérer donc ces éléments dans une autre page qui les injectera dans ma base de donnée.
J'essaie d'être le plus explicite possible, merci de votre aide.

Voici la page où le bon de commande est rempli :
<form method="POST" name="Form" autocomplete="OFF" enctype="multipart/form-data" action="voucher_ajouter.php">
<input type="hidden" name="action" value="send" />
<input type="hidden" name="access[]" value="home" />

<input type="text" name="Fr_Nom" id="Fr_Nom" value="">
<input type="text" name="Fr_Carte" id="Fr_Carte" value="">
<input type="text" name="Fr_Bon" id="Fr_Bon" value="">
<input type="text" name="Fr_Date" id="Fr_Date" value="">


<input type="hidden" name="Fr_Total" id="Resultat_input" value="0">
<input type="hidden" name="Fr_Pourcentage" id="Pourcentage_input" value="0">

<input type="submit" name="button" class="btn btn-large btn-primary" value="Valider le bon de commande" />


<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" id="TableauJaquery1" class="Tableau">
  <thead>
    <tr>
      <th align="center"><strong>Libellé</strong></th>
      <th width="80" align="center"><strong>Quantité</strong></th>
      <th width="100" align="center"><strong>Prix</strong></th>
      <th width="100" align="center"><strong>Total</strong></th>
    </tr>
  </thead>

  <tbody>
  <?php
$Stat = $pdo->query("SELECT * FROM " . $TB_PRODUITS . " WHERE " . $PAYS . "='1' AND Activer = 1 AND Stock = '1' ORDER BY Marque ASC; ");
$i    = 0;
while ($data = $Stat->fetch(PDO::FETCH_ASSOC)) {
?>
   <tr>
      <td align="left" valign="middle"><div style="display:none;"><?php
    echo $data["Libelle"] . " " . $data["Contenance"];
?></div>
        <input type="text" class="span2" id="Fr_Libelle_<?php
    echo $i;
?>" style="width:100%; text-align:left; margin:0;" readonly value="<?php
    echo $data["Libelle"] . " " . $data["Contenance"];
?>" >
      </td>
      <td align="center" valign="middle">
        <input type="text" class="span2" id="Fr_Quantite_<?php
    echo $i;
?>" style="width:100%; text-align:center; margin:0;" maxlength="2" value="0" oninput="calcul('<?php
    echo $i;
?>')">
      </td>
      <td align="right" valign="middle">
        <input type="text" class="span2" id="Fr_Prix_<?php
    echo $i;
?>" style="width:100%; text-align:right; margin:0;" maxlength="2" readonly value="<?php
    echo $data["Prix"];
?>" oninput="calcul('<?php
    echo $i;
?>')">
      </td>
      <td align="right" valign="middle">
        <input type="text" class="span2" id="Fr_Total_<?php
    echo $i;
?>" style="width:100%; text-align:right; margin:0;" maxlength="2" readonly value="0">
      </td>
    </tr>
    <?php
    $i++;
}
?>
 </tbody>
</table>
</div>
</form>


Et voici celle qui doit injecter les éléments dans ma table :
<?php
$Fr_Nom = trim(strip_tags($_POST["Fr_Nom"]));
$Fr_Carte = trim(strip_tags($_POST["Fr_Carte"]));
$Fr_Bon = trim(strip_tags($_POST["Fr_Bon"]));
$Fr_Date = trim(strip_tags($_POST["Fr_Date"]));
$Fr_Total = trim(strip_tags($_POST["Fr_Total"]));
$Fr_Pourcentage = trim(strip_tags($_POST["Fr_Pourcentage"]));
$Fr_Libelle = trim(strip_tags($_POST["Fr_Libelle"]));
$Fr_Quantite = trim(strip_tags($_POST["Fr_Quantite"]));
$Fr_PrixUnit = trim(strip_tags($_POST["Fr_PrixUnit"]));
$Fr_PrixTotal = trim(strip_tags($_POST["Fr_PrixTotal"]));

$Fr_Nom = !empty($Fr_Nom) ? "$Fr_Nom" : NULL;
$Fr_Carte = !empty($Fr_Carte) ? "$Fr_Carte" : NULL;
$Fr_Bon = !empty($Fr_Bon) ? "$Fr_Bon" : NULL;
$Fr_Date = !empty($Fr_Date) ? "$Fr_Date" : NULL;
$Fr_Total = !empty($Fr_Total) ? "$Fr_Total" : NULL;
$Fr_Pourcentage = !empty($Fr_Pourcentage) ? "$Fr_Pourcentage" : NULL;
$Fr_Libelle = !empty($Fr_Libelle) ? "$Fr_Libelle" : NULL;
$Fr_Quantite = !empty($Fr_Quantite) ? "$Fr_Quantite" : NULL;
$Fr_PrixUnit = !empty($Fr_PrixUnit) ? "$Fr_PrixUnit" : NULL;
$Fr_PrixTotal = !empty($Fr_PrixTotal) ? "$Fr_PrixTotal" : NULL;

$FR_PDO = $pdo->prepare("INSERT INTO tb_user_voucher (Nom, Carte, Bon, Date, Total, Pourcentage, Libelle, Quantite, PrixUnit, PrixTotal)
VALUES (:Fr_Nom, :Fr_Carte, :Fr_Bon, :Fr_Date, :Fr_Total, :Fr_Pourcentage, :Fr_Libelle, :Fr_Quantite, :Fr_PrixUnit, :Fr_PrixTotal)");
$FR_PDO->execute(array(
	"Fr_Nom" => $Fr_Nom,
	"Fr_Carte" => $Fr_Carte,
	"Fr_Bon" => $Fr_Bon,
	"Fr_Date" => $Fr_Date,
	"Fr_Total" => $Fr_Total,
	"Fr_Pourcentage" => $Fr_Pourcentage,
	"Fr_Libelle" => $Fr_Libelle,
	"Fr_Quantite" => $Fr_Quantite,
	"Fr_PrixUnit" => $Fr_PrixUnit,
	"Fr_PrixTotal" => $Fr_PrixTotal
));


Je sais que l'insert ajoute une ligne dans la table, mais ici, il faudrait que chaque ligne du tableau dont la valeur de la quantité est = à 0 s'enregistre avec les autres infos de l'utilisateur.

Pouvez-vous m'aider à résoudre ce problème svp ?

4 réponses

jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 4 650
6 juil. 2017 à 15:11
Du côté de ton tableau
while ($data = $Stat->fetch(PDO::FETCH_ASSOC)) {
?>
   <tr>
      <td align="left" valign="middle"><div style="display:none;"><?php echo $data["Libelle"] . " " . $data["Contenance"];?></div>
        <input type="text" name="Fr_Libelle[]" class="span2" id="Fr_Libelle_<?php echo $i;?>" style="width:100%; text-align:left; margin:0;" readonly value="<?php echo $data["Libelle"] . " " . $data["Contenance"];?>" >
      </td>
      <td align="center" valign="middle">
        <input type="text" name="Fr_Quantite[<?php echo $i;?>]" class="span2" id="Fr_Quantite_<?php echo $i;?>" style="width:100%; text-align:center; margin:0;" maxlength="2" value="0" oninput="calcul('<?php echo $i;?>')">
      </td>
      <td align="right" valign="middle">
        <input type="text" name="Fr_Prix[<?php echo $i;?>]" class="span2" id="Fr_Prix_<?php echo $i;?>" style="width:100%; text-align:right; margin:0;" maxlength="2" readonly value="<?php echo $data["Prix"];?>" oninput="calcul('<?php echo $i;?>')">
      </td>
      <td align="right" valign="middle">
        <input type="text" class="span2" id="Fr_Total_<?php echo $i;?>" style="width:100%; text-align:right; margin:0;" maxlength="2" readonly value="0">
      </td>
    </tr>
<?php
  $i++;
}
?>


et du côté de ton php, commence par regarder ce que donne :
print_r($_POST);

Tu devrais voir tous les données remplies ....
1
Sinistrus Messages postés 1017 Date d'inscription mercredi 12 décembre 2007 Statut Membre Dernière intervention 6 juin 2023 17
6 juil. 2017 à 15:17
le print_r me renvoi ceci :
Array ( [action] => send [access] => Array ( [0] => home ) [Fr_Total] => 13500 [Fr_Pourcentage] => 10800 [Fr_Code] => bd443acfdaa83835df9f6bac1575d66d [button] => Valider le bon de commande [TableauJaquery1_length] => 10 [Fr_Quantite_225] => 0 [Fr_Prix_225] => 3500 [Fr_Total_225] => 0 [Fr_Quantite_223] => 3 [Fr_Prix_223] => 2500 [Fr_Total_223] => 7500 [Fr_Quantite_234] => 2 [Fr_Prix_234] => 3000 [Fr_Total_234] => 6000 [Fr_Quantite_484] => 0 [Fr_Prix_484] => 0 [Fr_Total_484] => 0 [Fr_Quantite_405] => 0 [Fr_Prix_405] => 0 [Fr_Total_405] => 0 [Fr_Quantite_473] => 0 [Fr_Prix_473] => 0 [Fr_Total_473] => 0 [Fr_Quantite_474] => 0 [Fr_Prix_474] => 0 [Fr_Total_474] => 0 [Fr_Quantite_475] => 0 [Fr_Prix_475] => 0 [Fr_Total_475] => 0 [Fr_Quantite_476] => 0 [Fr_Prix_476] => 0 [Fr_Total_476] => 0 [Fr_Quantite_477] => 0 [Fr_Prix_477] => 0 [Fr_Total_477] => 0 )


Et ma table enregistre une ligne dont le libellé, quantité, prixunit et prixtotal sont vides.
J'ai remplis 2 lignes dans mon tableau, je dois normalement avoir 2 lignes dans ma table pour chaque quantité renseignée.
0
jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 4 650 > Sinistrus Messages postés 1017 Date d'inscription mercredi 12 décembre 2007 Statut Membre Dernière intervention 6 juin 2023
6 juil. 2017 à 16:41
Tu n'as pas repris mon code ...
Tu ne devrais pas avoir :
Fr_Quantite_225 ....;
Mais plutôt Fr_Quantite[225]
0
Sinistrus Messages postés 1017 Date d'inscription mercredi 12 décembre 2007 Statut Membre Dernière intervention 6 juin 2023 17
Modifié le 6 juil. 2017 à 16:57
si si, j'ai copié collé et vérifié !
name="Fr_Libelle[]"
name="Fr_Quantite[<?php echo $i;?>]"
name="Fr_Prix[<?php echo $i;?>]"
id="Fr_Total_<?php echo $i;?>" (là tu n'as pas mis de name je sais pas pourquoi)

et voilà le print_r
Array ( [action] => send [access] => Array ( [0] => home ) 
[Fr_Total] => 14000 [Fr_Pourcentage] => 11200
[Fr_Code] => bd443acfdaa83835df9f6bac1575d66d
[button] => Valider le bon de commande [TableauJaquery1_length] => 10
[Fr_Libelle] => Array ( [225] => Libellé A [223] => Libellé B [234] => Libellé C [484] => Libellé D [405] => Libellé E [473] => Libellé F [474] => Libellé G [475] => Libellé H [476] => Libellé I [477] => Libellé J )
[Fr_Quantite] => Array ( [225] => 0 [223] => 2 [234] => 3 [484] => 0 [405] => 0 [473] => 0 [474] => 0 [475] => 0 [476] => 0 [477] => 0 )
[Fr_Prix] => Array ( [225] => 3500 [223] => 2500 [234] => 3000 [484] => 0 [405] => 0 [473] => 0 [474] => 0 [475] => 0 [476] => 0 [477] => 0 ) )


Attends, c'est quoi cette embrouille ? Pourquoi là c'est différent ? le cache tu penses ?
0
jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 4 650 > Sinistrus Messages postés 1017 Date d'inscription mercredi 12 décembre 2007 Statut Membre Dernière intervention 6 juin 2023
Modifié le 6 juil. 2017 à 17:59
Moi j'ai écris :
<td align="right" valign="middle">
 <input type="text" 
           name="Fr_Prix[<?php echo $i;?>]" 
           class="span2" 
           id="Fr_Prix_<?php echo $i;?>" 
           style="width:100%; text-align:right; margin:0;" maxlength="2" readonly value="<?php echo $data["Prix"];?>" 
           oninput="calcul('<?php echo $i;?>')">
      </td>

là ... tu y vois DEUX attributs NAME ????
0
Sinistrus Messages postés 1017 Date d'inscription mercredi 12 décembre 2007 Statut Membre Dernière intervention 6 juin 2023 17
6 juil. 2017 à 18:04
Voici ma ligne :
<td align="right" valign="middle">
<input type="text"
name="Fr_Prix[<?php echo $i;?>]"
class="span2"
id="Fr_Prix_<?php echo $i;?>"
style="width:100%; text-align:right; margin:0;" maxlength="2" readonly value="<?php echo $data["Prix"];?>"
oninput="calcul('<?php echo $i;?>')">
</td>

Voici a ligne :
<td align="right" valign="middle">
<input type="text"
name="Fr_Prix[<?php echo $i;?>]"
class="span2"
id="Fr_Prix_<?php echo $i;?>"
style="width:100%; text-align:right; margin:0;" maxlength="2" readonly value="<?php echo $data["Prix"];?>"
oninput="calcul('<?php echo $i;?>')">
</td>
Je crois qu'il n'y a pas de différences.

J'ai dû t'envoyer un truc non rafraîchis je ne sais pas comment.

Tu veux tout mon code ? le voilà :
<?php  $Stat = $pdo->query("SELECT * FROM ".$TB_PRODUITS." WHERE ".$PAYS."='1' AND Activer = 1 AND Stock = '1' AND Prix <> 0 ORDER BY Marque ASC; ");
$i = 0;
while($data = $Stat->fetch(PDO::FETCH_ASSOC)){
	?>
<tr>
      <td align="left" valign="middle"><div style="display:none;"><?php echo $data["Libelle"]." ".$data["Contenance"];?></div>
        <input type="text" name="Fr_Libelle[]" class="span2" id="Fr_Libelle_<?php echo $i;?>" style="width:100%; text-align:left; margin:0;" readonly value="<?php echo $data["Libelle"]." ".$data["Contenance"];?>" >
      </td>
      <td align="center" valign="middle">
        <input type="text" name="Fr_Quantite[<?php echo $i;?>]" class="span2" id="Fr_Quantite_<?php echo $i;?>" style="width:100%; text-align:center; margin:0;" maxlength="2" value="0" oninput="calcul('<?php echo $i;?>')">
      </td>
      <td align="right" valign="middle">
        <input type="text" name="Fr_Prix[<?php echo $i;?>]" class="span2" onClick="this.select();" id="Fr_Prix_<?php echo $i;?>" style="width:100%; text-align:right; margin:0;" maxlength="2" readonly value="<?php echo $data["Prix"];?>" oninput="calcul('<?php echo $i;?>')">
      </td>
      <td align="right" valign="middle">
        <input type="text" class="span2" id="Fr_Total_<?php echo $i;?>" style="width:100%; text-align:right; margin:0;" maxlength="2" readonly value="0">
      </td>
    </tr>
<?php
  $i++;
}
?>
0
jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 4 650
5 juil. 2017 à 14:40
Bonjour,

Déjà.. commence par appliquer ceci :
https://forums.commentcamarche.net/forum/affich-37584941-php-pdo-gerer-les-erreurs

Puis reviens nous poster ton code modifié.
On verra ensuite pour le reste...

Sachant que pour le "reste" il faudra simplement mettre des attributs NAME à tes inputs sous forme d'array
par exemple :
 <input type="text" name = "Fr_Total[<?php echo $i;?>]" class="span2" id="Fr_Total_<?php echo $i;?>" style="width:100%; text-align:right; margin:0;" maxlength="2" readonly value="0">

Côté php .. tu n'auras plus qu'à boucler sur l'array pour les insérer en bdd...
$array_total = !empty($_POST['Fr_Total']) ? $_POST['Fr_Total'] : NULL;

foreach($array_total as $T){
  //.....
  //le temps des tests pour que tu vois ce que ça donne :
  // echo "<br>"; $T;
}


0
Sinistrus Messages postés 1017 Date d'inscription mercredi 12 décembre 2007 Statut Membre Dernière intervention 6 juin 2023 17
Modifié le 5 juil. 2017 à 15:02
J'ai ajouté l'attribut NAME aux inputs,
Pour la gestion des erreurs, c'est dans mon fichier config,
J'ai mis les lignes d'array comme ceci :
<?php
$Fr_Nom = trim(strip_tags($_POST["Fr_Nom"]));
$Fr_Carte = trim(strip_tags($_POST["Fr_Carte"]));
$Fr_Bon = trim(strip_tags($_POST["Fr_Bon"]));
$Fr_Date = trim(strip_tags($_POST["Fr_Date"]));
$Fr_Total = trim(strip_tags($_POST["Fr_Total"]));
$Fr_Pourcentage = trim(strip_tags($_POST["Fr_Pourcentage"]));

$Fr_Nom = !empty($Fr_Nom) ? "$Fr_Nom" : NULL;
$Fr_Carte = !empty($Fr_Carte) ? "$Fr_Carte" : NULL;
$Fr_Bon = !empty($Fr_Bon) ? "$Fr_Bon" : NULL;
$Fr_Date = !empty($Fr_Date) ? "$Fr_Date" : NULL;
$Fr_Total = !empty($Fr_Total) ? "$Fr_Total" : NULL;
$Fr_Pourcentage = !empty($Fr_Pourcentage) ? "$Fr_Pourcentage" : NULL;
$array_libelle = !empty($_POST['Fr_Libelle']) ? $_POST['Fr_Libelle'] : NULL;
$array_quantite = !empty($_POST['Fr_Quantite']) ? $_POST['Fr_Quantite'] : NULL;
$array_unit = !empty($_POST['Fr_PrixUnit']) ? $_POST['Fr_PrixUnit'] : NULL;
$array_total = !empty($_POST['Fr_PrixTotal']) ? $_POST['Fr_PrixTotal'] : NULL;

$FR_PDO = $pdo->prepare("INSERT INTO tb_user_voucher (Nom, Carte, Bon, Date, Total, Pourcentage, Libelle, Quantite, PrixUnit, PrixTotal)
VALUES (:Fr_Nom, :Fr_Carte, :Fr_Bon, :Fr_Date, :Fr_Total, :Fr_Pourcentage, :Fr_Libelle, :Fr_Quantite, :Fr_PrixUnit, :Fr_PrixTotal)");
$FR_PDO->execute(array(
	"Fr_Nom" => $Fr_Nom,
	"Fr_Carte" => $Fr_Carte,
	"Fr_Bon" => $Fr_Bon,
	"Fr_Date" => $Fr_Date,
	"Fr_Total" => $Fr_Total,
	"Fr_Pourcentage" => $Fr_Pourcentage,
	"Fr_Libelle" => $Fr_Libelle,
	"Fr_Quantite" => $Fr_Quantite,
	"Fr_PrixUnit" => $Fr_PrixUnit,
	"Fr_PrixTotal" => $Fr_PrixTotal
));
Et là je suis bloqué :D
0
jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 4 650 > Sinistrus Messages postés 1017 Date d'inscription mercredi 12 décembre 2007 Statut Membre Dernière intervention 6 juin 2023
5 juil. 2017 à 16:17
Pour la gestion des erreurs, c'est dans mon fichier config,

Pas que .....
Si tu avais bien lu la doc que je t'ai donné... tu verrais qu'il te manque un bloc TRY/CATCH au niveau de l’exécution de ta requête...

Pour ce qui est de ton souci...
Fais donc un
print_r($Fr_Total);
et regarde ce que ça te donne.....

Au passage... tu me confirmes que tu sais ce qu'est un ARRAY et comment boucler dessus ??
0
Sinistrus Messages postés 1017 Date d'inscription mercredi 12 décembre 2007 Statut Membre Dernière intervention 6 juin 2023 17
5 juil. 2017 à 16:29
Try et catch comme ce qui est dans mon fichier config ?
try{$pdo = new PDO('mysql:host='.MYSQL_HOST.';dbname='.MYSQL_BASE, MYSQL_USER, MYSQL_PASS);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec("SET CHARACTER SET utf8");} catch(PDOException $e) {echo "Erreur: ".$e->getMessage();} error_reporting(E_ALL); ini_set('display_errors', true);


Ou je dois quand même l'ajouter à la fin de ma requête comme sur le lien que tu m'as donné ?

Le
print_r($Fr_Total);
me donnera une valeur unique comme le pseudo. Je fais un
print_r($Fr_PrixTotal);
et voici le résultat : 0

Il enregistre une ligne dans ma table bien entendu, mais tout ce qui fait parti du tableau est soit NULL soit 0
0
jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 4 650 > Sinistrus Messages postés 1017 Date d'inscription mercredi 12 décembre 2007 Statut Membre Dernière intervention 6 juin 2023
5 juil. 2017 à 16:32

comme sur le lien que tu m'as donné ?
A ton avis ..... Si c'est dans le lien que je t'ai donné.....

Concernant ton souci...
Peux tu faire un
print_r($_POST);

et nous montrer ce que ça donne ??

Faudrait aussi que nous nous montres le code de ton formulaire (celui que tu as désormais avec les "name" pour tes inputs )
0
jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 4 650 > jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024
5 juil. 2017 à 16:34
Pour être sûr de bien comprendre ...
Tu veux, lorsque tu cliques sur le bouton submit :
- Enregistrer les premiers input que tu as dans ton formulaire ... mais aussi tous ceux que tu génères avec ta boucle ???


Ne serait pas plutôt :
- Enregistrement des premiers input
- Mise à jour, dans la bdd, des inputs générés par ta boucle php

???
0
Sinistrus Messages postés 1017 Date d'inscription mercredi 12 décembre 2007 Statut Membre Dernière intervention 6 juin 2023 17
7 juil. 2017 à 11:53
Ca y est ! j'ai enfin réussi grâce à toi !
$FR_PDO = $pdo->prepare("INSERT INTO tb_user_voucher (Nom, Carte, Pseudo, Email, Code, Date, NetPayer, Pourcentage, Libelle, Quantite, PrixUnit, PrixTotal)
VALUES (:Fr_Nom, :Fr_Carte, :Fr_Pseudo, :Fr_Email, :Fr_Code, :Fr_Date, :Fr_NetPayer, :Fr_Pourcentage, :array_lib, :array_qte, :array_unt, :array_tot)");
foreach($array_lib as $key => $value)
{
 	$FR_PDO->execute(array(
		":Fr_Nom" => $Fr_Nom,
		":Fr_Carte" => $Fr_Carte,
		":Fr_Pseudo" => $Fr_Pseudo,
		":Fr_Email" => $Fr_Email,
		":Fr_Code" => $Fr_Code,
		":Fr_Date" => $Fr_Date,
		":Fr_NetPayer" => $Fr_NetPayer,
		":Fr_Pourcentage" => $Fr_Pourcentage,
		":array_lib" => $value,
		":array_qte" => $array_qte[$key],
		":array_unt" => $array_unt[$key],
		":array_tot" => $array_tot[$key]
	));
}

Je rencontre tout de même un dernier petit soucis, Undefined offset: 8 sur les lignes :
":array_qte" => $array_qte[$key],
":array_unt" => $array_unt[$key],
":array_tot" => $array_tot[$key]

Pourtant je penses avoir définit la valeur 0 !
$array_qte = !empty($_POST['Fr_Quantite']) ? $_POST['Fr_Quantite'] : 0;
$array_unt = !empty($_POST['Fr_PrixUnit']) ? $_POST['Fr_PrixUnit'] : 0;
$array_tot = !empty($_POST['Fr_PrixTotal']) ? $_POST['Fr_PrixTotal'] : 0;

Afin de me faciliter l'injection de ma requête de mes 800 articles, y aurait-il moyen de limiter l'injection selon si les quantité sont 0 alors il n'ajoute pas la ligne ?

Par exemple, j'ai :
Libellé    | Quantité | Prix Unit. |Prix Total |
------------------------------------------------
Libellé 1 | 2 | 200 | 400 |
Libellé 2 | 0 | 300 | 0 |
Libellé 3 | 1 | 100 | 100 |

Il n'ajoutera que Libellé 1 et Libellé 3 ?
0
jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 4 650
7 juil. 2017 à 11:56
foreach($array_lib as $key => $value)
{
 	$FR_PDO->execute(array(
		":Fr_Nom" => $Fr_Nom,
		":Fr_Carte" => $Fr_Carte,
		":Fr_Pseudo" => $Fr_Pseudo,
		":Fr_Email" => $Fr_Email,
		":Fr_Code" => $Fr_Code,
		":Fr_Date" => $Fr_Date,
		":Fr_NetPayer" => $Fr_NetPayer,
		":Fr_Pourcentage" => $Fr_Pourcentage,
		":array_lib" => $value,
		":array_qte" => !empty($array_qte[$key]) ? $array_qte[$key] : 0,
		":array_unt" => !empty($array_unt[$key]) ? $array_unt[$key] : 0,
		":array_tot" => !empty($array_tot[$key]) ? $array_tot[$key] : 0
	));
}
0
jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 4 650
7 juil. 2017 à 11:57

Afin de me faciliter l'injection de ma requête de mes 800 articles, y aurait-il moyen de limiter l'injection selon si les quantité sont 0 alors il n'ajoute pas la ligne ?

Tu n'a qu'à faire un IF avant de faire (ou non..) la requête...
0
Sinistrus Messages postés 1017 Date d'inscription mercredi 12 décembre 2007 Statut Membre Dernière intervention 6 juin 2023 17
7 juil. 2017 à 21:28
Je considère le sujet résolu grâce à ton aide. Merci Jordan encore une fois !
0