Partage
  • Partager sur Facebook
  • Partager sur Twitter

cannot redeclare function supposedly previously

cannot redeclare function supposedly previously declared

Sujet résolu
    19 novembre 2019 à 20:23:47

    Bonjour,

    Pour mon projet je dois réaliser un panier d'achat, j'ai créé un jeu d'essai, un fichier de fonction pour mon panier et un autre fichier avec les autres fonctions (connexion ...).

    Lorsque que je veux ajouter un produit au panier je trouve cette erreur 'Cannot redeclare MontantGlobal() (previously declared in'.

    J'ai essayé le include_once, d'enlever temporairement cette fonction mais le problème venait avec une autre. Je pense donc que le problème vient de mes déclarations mais après avoir passé au peigne fin, je ne trouve aucune anomalie, c'est pour ça que j'ai besoin de votre aide. (Je suis en modèle MCV si ça peut changer quelque chose)

    Merci

    Fonctions.php

    <?php
    function Connexion()
    {
        $serveur="localhost";
        $nom="root";
        $motpasse="";
        $base="slam4act2_fevrier";
        try
        {
            $connect = new PDO("mysql:host=".$serveur.";dbname=".$base, $nom, $motpasse);
        }
        Catch(PDOException $e)
        {
            echo "Impossible de se connecter!".$e -> getMessage();
        }
        return $connect;
    }
    
    function Deconnexion($connect)
    {
        if($connect)
            $connect= NULL;
    }
    
    function UpdateDelete($query)
    {
        $connect=Connexion();
        $result=$connect->exec($query);
        Deconnexion($connect);
        return $result;
    }
    
    function Select($table)
    {
        $connect=Connexion();
        $query="select * from ".$table;
        $result = $connect -> query($query);
        Deconnexion($connect);
        return $result;
    }
    
    function SelectUnCritere($table, $champ1, $critere1)
    {
        $connect=Connexion();
        $query="select * from ".$table." where ".$champ1."= '".$critere1."'";
        $result = $connect -> query($query);
        Deconnexion($connect);
        return $result;
    }
    
    function SelectCritere($table, $champ1, $critere1, $champ2, $critere2)
    {
        $connect=Connexion();
        $query="select * from ".$table." where ".$champ1."='".$critere1."' and ".$champ2."='".$critere2."'";
        $result = $connect->query($query);
        Deconnexion($connect);
        return $result;
    }
    
    function SelectUnCritereAES($table, $champ1, $critere1)
    {
        $connect=Connexion();
        $crypt ="AES_ENCRYPT('".$critere1."','clefsecrete')";
        $query="select * from ".$table." where ".$champ1."= ".$crypt;
        $result = $connect->query($query);
        Deconnexion($connect);
        return $result;
    }
    
    function Insert($tableau, $query)
    {
        $connect=Connexion();
        $query= $connect->prepare($query);
        $result = $query->execute($tableau);
        Deconnexion($connect);
        return $result;
    }
    
    function chaine_aleatoire($nb_car, $chaine = 'azertyuiopqsdfghjklmwxcvbn123456789')
    {
        $nb_lettres = strlen($chaine) - 1;
        $generation = '';
        for($i=0; $i < $nb_car; $i++)
        {
            $pos = mt_rand(0, $nb_lettres);
            $car = $chaine[$pos];
            $generation .= $car;
        }
        return $generation;
    }
    ?>


    FonctionsPanier.php

    <?php
    /**
     * Création du panier
     * @return void
     */
    function creationPanier()
    {
    $_SESSION['panier']=array();
    $_SESSION['panier']['NumProduit']=array();
    $_SESSION['panier']['LibelleProduit']=array();
    $_SESSION['panier']['QteProduit']=array();
    $_SESSION['panier']['PrixProduit']=array();
    $_SESSION['panier']['Verrou']=false;
    }
    
    /**
     * Teste si le panier est verrouillé (true) dans le but d'empecher toutes actions sur le panier
     * @return boolean
     */
    
    function isVerrouille()
    {
        if(isset($_SESSION['panier']) && $_SESSION['panier']['Verrou']==true)
        return true;
    else
        return false;
    }
    
    /**
     * Compte le nombre d'articles différents dans le panier
    * @return int
    */
    
    function compterArticles()
    {
        if(isset($_SESSION['panier']))
        return count($_SESSION['panier']['NumProduit']);
    else
        return 0;
    }
    
    /**
     * Suppression du panier
     * @return void
     */
    function supprimePanier()
    {
       session_unset(); 
    }
    
    /**
     * Compte le nombre total d'articles dans le panier
     * @return int
     */
    
    function compterQteArticles()
    {
        $total=0;
        if(isset($_SESSION['panier']))
        {
            /////////////////////
            ////////////////////////////pas de count
            for($i=$total;$i<compterArticles(); $i++)
            {
                $total = $_SESSION['panier']['NumProduit']['QteProduit'];
            }
        }
        return($total);
    }
    
    /////////////////////
    //////////////////////Manque paramètres
    function ajouterArticle($numProduit, $libelleproduit, $prixproduit)
    {
        if (!isset($_SESSION['panier']))
        {
            creationPanier();
            array_push( $_SESSION['panier']['NumProd'],$numProduit);
            array_push( $_SESSION['panier']['LibelleProd'],$libelleproduit);
            array_push( $_SESSION['panier']['QteProd'],$qteproduit);
            array_push( $_SESSION['panier']['PrixProd'],$prixproduit);
            return true;
        }
        else if (isVerrouille() == true)
        {
            echo "Panier verrouillé";
            return true;
        }
        else
        {
            $positionProduit = array_search($numproduit,  $_SESSION['panier']['NumProd']);
            if($positionProduit !== false)
            {
                $_SESSION['panier']['QteProd'][$positionProduit] +=1;
            }
            else
            {
                array_push( $_SESSION['panier']['NumProd'],$numproduit);
                array_push( $_SESSION['panier']['LibelleProd'],$libelleproduit);
                array_push( $_SESSION['panier']['QteProd'],1);
                array_push( $_SESSION['panier']['PrixProd'],$prixproduit);
            }
            ///////////////////////
            return true;
        }
    }
    
    /**
     * Supprime un article du panier
     * @param $numProduit
     * @return void
     */
    
    function supprimerArticle($numProduit)
    {
        ////////////////////
        //////////////////////isset=true
        if(!isset($_SESSION['panier']) && isVerrouille() == false)
        {
            $positionProduit = array_search($numproduit,  $_SESSION['panier']['NumProd']);
            //Detruire le numéro de produit
            unset($_SESSION['panier']['NumProduit'][$positionProduit]);
            $_SESSION['panier']['NumProduit'] = array_values($_SESSION['panier']['NumProduit']);
    
            //Detruire le libelle du produit
            unset($_SESSION['panier']['LibelleProd'][$positionProduit]);
            $_SESSION['panier']['LibelleProd'] = array_values($_SESSION['panier']['LibelleProd']);
    
            //Detruire la quantite du produit
            unset($_SESSION['panier']['QteProd'][$positionProduit]);
            $_SESSION['panier']['QteProd'] = array_values($_SESSION['panier']['QteProd']);
    
            //Detruire le prix du produit
            unset($_SESSION['panier']['PrixProd'][$positionProduit]);
            $_SESSION['panier']['PrixProd'] = array_values($_SESSION['panier']['PrixProd']);
        }
        else
        {
            echo"La panier n'existe pas ou est verrouillé";
        }
    }
    
    
    /**
     * Montant total du panier en fonction des quantités de chaque produit
     * @return float
     */
    function MontantGlobal()
    {
        $total=0;
    
        ////////////////////////
        ///////////////////// de 0 à !!!!
        for($i=0;$i<=compterQteArticles();$i++)
        {
            $total += $_SESSION['panier']['QteProd'][$i] * $_SESSION['panier']['PrixProduit'][$i];
        }
        return $total;
    }

    Category.php

    <?php
    	include('FonctionsPanier.php');
    	include('../Model/Fonctions.php');
    	$result=Select('produit');
    	$result->execute();
    	if(isset($_GET['ajout']) && !empty($_GET['ajout']))
    	{
    		$selectProd=SelectUnCritere('produit', 'NumProd', $_GET['ajout']);
    		while($row=$selectProd->fetch())
    		{
    			$num = $row['NumProd'];
    			$libelle = $row['LibelleProd'];
    			$prix = $row['PrixProd'];
    		}
    
    		if(creationPanier() == true)
    		{
    			echo'<div class="alert alert-success" role="alert"><strong>'.$libelle.'</strong> Ajouté au panier avec succès pour un montant de <strong>'.$prix.' € </strong></div>';
    			echo '<meta http-equip="refresh" content="5; URL="category.php">';
    		}
    		else
    		{
    			echo'<div class="alert alert-danger" role="alert"><strong>'.$libelle.'</strong> na pas pu etre ajouté au panier !</div>';
    			echo '<meta http-equip="refresh" content="2; URL="category.php">';
    		}
    	}
    	include('../View/categoryView.php');
    ?>
    

    categoryView.php

    <!-- single product -->
    						<?php
    							while($row = $result->fetch())
    							{
    						?>
    								<div class="col-lg-4 col-md-6">
    									<div class="single-product">
    										<img class="img-fluid" src="../img/product/<?php echo $row['ImageProd'];?>" alt="">
    											<div class="product-details">
    												<h6><?php echo $row['LibelleProd']; ?></h6>
    													<div class="price">
    														<h6> <?php echo $row['PrixProd']; ?> €</h6>
    													</div>
    													<div class="prd-bottom">
    														<form id="form<?php echo $row['NumProd'];?>" action="category.php?ajout=<?php echo $row['NumProd'];?>" method="POST">
    															<a href="#" class="social-info" onclick="document.getElementById('form<?php echo $row['NumProd'];?>').submit();">
    															<span class="ti-bag"></span>
    															<p class="hover-text">Ajouter au panier</p>
    															</a>
    														</form>
    													</div>
    											</div>
    									</div>
    								</div>
    <?php
    }
    ?>






    • Partager sur Facebook
    • Partager sur Twitter

    cannot redeclare function supposedly previously

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown