Wrong datatype for second argument in

Fermé
johny88888 - 10 mars 2011 à 13:15
 johny88888 - 10 mars 2011 à 21:51
Bonjour,

J'ai un message d'erreur lors de l'ajout d'un article:

Warning: array_search() [function.array-search]: Wrong datatype for second argument in /web/bike4lifeshop/www/fonctions-panier.php on line 36

Warning: array_push() [function.array-push]: First argument should be an array in /web/bike4lifeshop/www/fonctions-panier.php on line 45

Warning: array_push() [function.array-push]: First argument should be an array in /web/bike4lifeshop/www/fonctions-panier.php on line 47

La valeur de recherche est un numéro d'article.

function ajouterArticle($idProduit,$photoProduit,$marque,$libelleProduit,$option,$qteProduit,$prixProduit){

   //Si le panier existe
   if (creationPanier() && !isVerrouille())
   {
      //Si le produit existe déjà on ajoute seulement la quantité
 //ligne36      $positionProduit = array_search($idProduit, $_SESSION['panier']['idProduit']);

      if ($positionProduit !== false)
      {
        $_SESSION['panier']['qteProduit'][$positionProduit] += $qteProduit ;
      }
      else
      {
         //Sinon on ajoute le produit
//ligne45	 array_push( $_SESSION['panier']['idProduit'],$idProduit);	 
         array_push( $_SESSION['panier']['photoProduit'],$photoProduit);
//ligne47		 array_push( $_SESSION['panier']['marque'],$marque);
         array_push( $_SESSION['panier']['libelleProduit'],$libelleProduit);
		 array_push( $_SESSION['panier']['option'],$option);
         array_push( $_SESSION['panier']['qteProduit'],$qteProduit);
         array_push( $_SESSION['panier']['prixProduit'],$prixProduit);

      }
   }
   else
   echo "Un problème est survenu veuillez contacter l'administrateur du site.";
}


je ne comprend pas pourquoi il met ça, si je change idproduit par libelleproduit plus d'erreur !!! est ce parce que c'est un chiffre?

Merci de votre aide


2 réponses

Merci pour ton aide, après encore avoir chercher 3h j'ai coupé le pc et recommencer un peu plus tard et résultat ca marche.

A bientot
1
Zep3k!GnO Messages postés 2025 Date d'inscription jeudi 22 septembre 2005 Statut Membre Dernière intervention 18 novembre 2015 200
10 mars 2011 à 17:31
Les messages d'erreurs sont super explicites quand même... Wrong datatype for second argument mmm ca voudrait pas dire que t'as un mauvais type de variable en second argument de la fonction ??
Et pour savoir le bon type : https://www.php.net/array_search
Et maintenant, regarde le type de ta variable avec un var_dump($_SESSION['panier']['idProduit']);

Tu vas tout débugger comme ça ;)
0