Insert et foreach : Undefined offset: 0

Résolu/Fermé
Sinistrus Messages postés 1017 Date d'inscription mercredi 12 décembre 2007 Statut Membre Dernière intervention 6 juin 2023 - Modifié le 4 janv. 2019 à 18:24
Sinistrus Messages postés 1017 Date d'inscription mercredi 12 décembre 2007 Statut Membre Dernière intervention 6 juin 2023 - 5 janv. 2019 à 00:13
Bonjour à tous et meilleurs vœux pour cette année !

J'ai un soucis de
undefined offset
dans mon code et je n'arrives pas à résoudre le problème. Pouvez-vous m'aider svp ?

$array_lib = !empty($_POST['Fr_Libelle']) ? $_POST['Fr_Libelle'] : array();
$array_qte = !empty($_POST['Fr_Quantite']) ? $_POST['Fr_Quantite'] : array();
$array_Poids = !empty($_POST['Fr_Poids']) ? $_POST['Fr_Poids'] : array();
$array_Poid_Total = !empty($_POST['Fr_Poid_Total']) ? $_POST['Fr_Poid_Total'] : array();
$array_pri = !empty($_POST['Fr_PrixUnit']) ? $_POST['Fr_PrixUnit'] : array();
$array_PrixTotal = !empty($_POST['Fr_PrixTotal']) ? $_POST['Fr_PrixTotal'] : array();
$array_rmz = !empty($_POST['Fr_Promo']) ? $_POST['Fr_Promo'] : array();
$Fr_Total_Produits = !empty($_POST['Fr_Total_Produits']) ? $_POST['Fr_Total_Produits'] : NULL;
$Fr_Poids_Total = !empty($_POST['Fr_Poids_Total']) ? $_POST['Fr_Poids_Total'] : NULL;
$Fr_Frais_Livraison = !empty($_POST['Fr_Frais_Livraison']) ? $_POST['Fr_Frais_Livraison'] : NULL;
$Fr_Frais_Payement = !empty($_POST['Fr_Frais_Payement']) ? $_POST['Fr_Frais_Payement'] : NULL;
$Fr_Net_A_Payer = !empty($_POST['Fr_Net_A_Payer']) ? $_POST['Fr_Net_A_Payer'] : NULL;
$Fr_Adresse_Livraison = $ADRESSE;
$Fr_Zone_Livraison = !empty($_POST['Fr_Zone_Livraison']) ? $_POST['Fr_Zone_Livraison'] : NULL;
$Fr_Secteur = !empty($_POST['Fr_Secteur']) ? $_POST['Fr_Secteur'] : NULL;
$Fr_Mode_Livraison = !empty($_POST['Fr_Mode_Livraison']) ? $_POST['Fr_Mode_Livraison'] : NULL;
$Fr_Mode_Payement = !empty($_POST['Fr_Mode_Payement']) ? $_POST['Fr_Mode_Payement'] : NULL;


try {
$Fact_FA = $pdo - > prepare("INSERT INTO tb_shop_FA (NIC_Handle, Date, Reference, Libelle_TAG, Quantite, Poids, Poids_STotal, Prix_Unitaire, Prix_Total, Remise, Total_Produits, Grand_Total, Poids_Total, Frais_Livraison, Frais_Payement, Net_A_Payer, Adresse_Livraison, Zone_Livraison, Secteur, Mode_Livraison, Mode_Payement) VALUES(Fr_NIC_Handle,: Fr_Date,: Fr_Reference,: array_lib,: array_qte,: array_Poids,: array_Poid_Total,: array_pri,: array_PrixTotal,: array_rmz,: Fr_Total_Produits,: Fr_Grand_Total,: Fr_Poids_Total,: Fr_Frais_Livraison,: Fr_Frais_Payement,: Fr_Net_A_Payer,: Fr_Adresse_Livraison,: Fr_Zone_Livraison,: Fr_Secteur,: Fr_Mode_Livraison,: Fr_Mode_Payement)");

    foreach($array_lib as $keyFA => $value) {
        if ($array_qte[$keyFA] < > 0) {

            $Fact_FA - > execute(array(
                "Fr_NIC_Handle" => $Fr_NIC_Handle,
                "Fr_Date" => $Fr_Date,
                "Fr_Reference" => $Fr_Reference,
                "array_lib" => $value,
                "array_qte" => $array_qte[$keyFA],
                "array_Poids" => $array_Poids[$keyFA],
                "array_Poid_Total" => $array_Poid_Total[$keyFA],
                "array_pri" => $array_pri[$keyFA],
                "array_PrixTotal" => $array_PrixTotal[$keyFA],
                "array_rmz" => $array_rmz[$keyFA],
                "Fr_Total_Produits" => $Fr_Total_Produits,
                "Fr_Grand_Total" => $Fr_Grand_Total,
                "Fr_Poids_Total" => $Fr_Poids_Total,
                "Fr_Frais_Livraison" => $Fr_Frais_Livraison,
                "Fr_Frais_Payement" => $Fr_Frais_Payement,
                "Fr_Net_A_Payer" => $Fr_Net_A_Payer,
                "Fr_Adresse_Livraison" => $Fr_Adresse_Livraison,
                "Fr_Zone_Livraison" => $Fr_Zone_Livraison,
                "Fr_Secteur" => $Fr_Secteur,
                "Fr_Mode_Livraison" => $Fr_Mode_Livraison,
                "Fr_Mode_Payement" => $Fr_Mode_Payement
            ));
        }};

} catch (PDOException $e) {echo "Erreur: ".$e - > getMessage();}


L'erreur se trouve sur cette ligne (126) :
if($array_qte[$keyFA] <> 0){
et voici ce que print_r me donne :

Notice: Undefined offset: 0 in /home/sivopnetbi/www/shop/_shop-upp.php on line 126
Notice: Undefined offset: 1 in /home/sivopnetbi/www/shop/_shop-upp.php on line 126

Array ( [NumId] => 1 [action] => send [access] => Array ( [0] => home ) [Fr_Libelle] => Array ( [0] => EAU-DE-TOILETTE-AVIATOR-AUTHENTIC-VAPORISATEUR-DE-100ML [1] => DEODORANT-CHAIRMAN-BLUE-FLACON-DE-200ML ) [Fr_NumId] => Array ( [0] => 3 [1] => 20 ) [Fr_PrixUnit] => Array ( [0] => 6825 [1] => 1425 ) [Fr_Promo] => Array ( [0] => 15 [1] => 15 ) [Fr_PrixTotal] => Array ( [0] => 17403.75 [1] => 2422.5 ) [Fr_Poids] => Array ( [0] => 0.45542 [1] => 0.16167 ) [Fr_Poid_Total] => Array ( [0] => 1.36626 [1] => 0.32334 ) [Fr_Mode] => on [Fr_Total_Produits] => 19826.25 [Fr_Poids_Total] => 1.690 [Fr_Frais_Livraison] => 0 [Fr_Frais_Payement] => 0 [Fr_Net_A_Payer] => 19826.25 [Fr_Zone_Livraison] => SIVOP [Fr_Secteur] => [Fr_Mode_Livraison] => [Fr_Mode_Payement] => )


Merci de votre aide et encore une fois, bonne et heureuse année !

Configuration: Windows / Chrome 71.0.3578.98

1 réponse

NHenry Messages postés 15112 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 13 avril 2024 330
4 janv. 2019 à 18:04
Quel est le code en ligne 126 ?
1
Sinistrus Messages postés 1017 Date d'inscription mercredi 12 décembre 2007 Statut Membre Dernière intervention 6 juin 2023 17
4 janv. 2019 à 18:07
Bonjour NHenry,

C'est cette ligne :
if($array_qte[$keyFA] <> 0){
0
NHenry Messages postés 15112 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 13 avril 2024 330
4 janv. 2019 à 23:11
Tu es sûr que c'est un tableau ?
As-tu tenté un print_r sur les sources et lister les items de ton tableau "array_qte" ?
0
Sinistrus Messages postés 1017 Date d'inscription mercredi 12 décembre 2007 Statut Membre Dernière intervention 6 juin 2023 17
5 janv. 2019 à 00:13
NHenry, merci beaucoup de t'intéresser à mon soucis. J'ai compris pourquoi j'ai eu cette erreur (il y a 5mn).
J'avais mis Fr_Quantite en disabled dans le html... voilà pourquoi il retournais cette erreur.

Le problème a été résolu et je te remercie encore une fois.
0