8725 sujets

Développement web côté serveur, CMS

Bonsoir,

Je rencontre encore un problème que je ne m'explique pas. J'ai encore une fois chercher pourquoi, en vain.
C'est pourquoi j'en appel encore une fois à votre aide.
D'avance merci de vote aide.

J'ai un système de panier qui fonctionne très bien en local, mais une fois le site en ligne, pas moyen de visualiser mon panier.
Mon site est hébergé chez PlanetHoster et mes scripts de connexion à la BDD sont bien corrects.

Je vais essayer de vous communiquer le maximum d'info sur mes scripts !

1°) J'ai un espace donateur qui m'affiche les produits à sélectionner pour le panier. Celui-ci est OK en local et en ligne. Il renvoie au panier "1_panier.php sur clic sur le bouton "ajouter au panier". Voici le code de ce fichier ainsi que du fichier "addpanier.php" qui est lié et bien sûr le fichier "1_panier.php" qui ne fonctionne pas :

Fichier "1_espace_donateur.php"

<?php require_once('ajout.php'); ?>

<?php

echo '<pre>';
print_r($_GET);
echo '</pre>';

if (!empty($_GET['prenomclient']) && ($_GET['nomclient'])) {
    $prenomclient = ($_GET['prenomclient']);
    $nomclient = ($_GET['nomclient']);

    $statement = $bdd->prepare("SELECT * FROM client WHERE nomclient = ?");
    $statement->execute(array($nomclient));
    $item = $statement->fetch();
    $codeagence         = $item['codeagence'];
    $prenomclient       = $item['prenomclient'];
    $mailclient         = $item['mailclient'];
    $telclient          = $item['telclient'];
    $nomclient          = $item['nomclient'];
    $prenomconjoint     = $item['prenomconjoint'];
    $nomconjoint        = $item['nomconjoint'];
    $mailconjoint       = $item['mailconjoint'];
    $telconjoint        = $item['telconjoint'];
    $nomevenement       = $item['nomevenement'];
}

?>

<div class="container">
    <div class="row">
        <div class="rounded col-lg-12 text-justify">
            <h1 class="rounded text-center mt-2 pt-4 pb-4 btn-primary"> Liste cadeaux de : <br>
                <strong><?php
                        $clients = $DB->query('SELECT * FROM client WHERE nomclient="' . $nomclient . '"');
                        foreach ($clients as $client) :
                            echo ucfirst($client->prenomclient) . " " . strtoupper($client->nomclient) . " et " . ucfirst($client->prenomconjoint) . " " . strtoupper($client->nomconjoint)  ?>
                    <?php endforeach ?> <br></strong>
                <a href="logout.php" class="mt-4 btn btn-danger">Déconnexion</a>
            </h1>

            <div class="row mb-4">
                <?php
                if (!empty($_POST['nomclient'])) {
                    $nomclient = ($_POST['nomclient']);
                }
                $statement = $bdd->prepare('SELECT * FROM client  WHERE nomclient="' . $nomclient . '"');
                $statement->execute();
                while ($item = $statement->fetch()) {
                    echo '<div class="col-lg-6"><img class="rounded" src="../img/clients/' . $item['imgclient'] . '" alt=" "> </div>';
                    echo '<div class="col-lg-6">' . $item['message'] . '<blockquote class="blockquote text-right"> <footer class="blockquote-footer">' . $item['prenomclient'] . ' ' . $item['nomclient'] . ' et ' . $item['prenomconjoint'] . ' ' . $item['nomconjoint'] .  '<br><cite title="Source Title"> Merci  pour votre participation au voyage de nos rêves !</cite</footer></blockquote> </div>';
                }

                ?>
            </div>
            <div class="col-lg-12 mt-4">
                <h4>
                    Voici la liste des produits que nous avons choisis pour agrémenter notre voyage. Vous pourrez choisir celui ou ceux que vous souhaitez nous offrir à l'occasion de notre <?php echo $nomevenement; ?>
                </h4>
            </div>
            <div class="row">
                <?php $produits = $DB->query('SELECT C.prenomclient, C.nomclient, P.ProduitID, P.nomproduit, P.prixproduit, P.imgproduit, T.nomtheme, V.nomvoyage FROM produit P JOIN client C ON C.nomclient = P.nomclient JOIN theme T ON T.nomtheme = P.nomtheme JOIN voyage V ON V.nomvoyage = P.nomvoyage WHERE C.nomclient="' . $nomclient . '"');
                foreach ($produits as $produit) :
                ?>
                    <div class="col-lg-4 mb-3">
                        <div class="card">
                            <img class="card-img-top" src="../img/produits/<?= $produit->imgproduit; ?>" alt="Produit liste cadeau Onelist">
                            <div class="card-header"><b> <?= $produit->nomproduit; ?> </b></div>
                            <div class="card-body">
                                <class="card-title"><?= $produit->nomtheme; ?><br>
                                    <p class="card-text"><?= $produit->nomvoyage; ?></p>
                                    <b>Prix par personne : <?= $produit->prixproduit; ?> €</b> <br>
                            </div>
                            <div class="card-footer text-center">
                                <a class="add addPanier" href="addpanier.php?ProduitID=<?= $produit->ProduitID . '&prenomclient=' . $prenomclient . '&nomclient=' . $nomclient; ?>"> <input type="button" class="btn btn-primary btn-block" value="Ajouter au panier" onClick="window.location.href='1_panier.php?ProduitID=<?= $produit->ProduitID . '&prenomclient=' . $prenomclient . '&nomclient=' . $nomclient . '&codeagence=' . $codeagence; ?>'"> </a>
                            </div>
                        </div>
                    </div>
                <?php endforeach ?>
            </div>
            <div class="col-lg-12">
                <section class="jumbotron text-center">
                    <div>
                        <?php
                        echo '<form method="get" action="1_panier.php" role="form">';
                        echo '<input id="codeagence" type="hidden" name="codeagence" value="' . $codeagence . '"> ';
                        echo '<input id="prenomclient" type="hidden" name="prenomclient" value="' . $prenomclient . '"> ';
                        echo '<input id="nomclient" type="hidden" name="nomclient" value="' . $nomclient . '"> ';
                        echo '<input id="prenomconjoint" type="hidden" name="prenomconjoint" value="' . $prenomconjoint . '"> ';
                        echo '<input id="nomconjoint" type="hidden" name="nomconjoint" value="' . $nomconjoint . '"> ';
                        echo '<input type="submit" class="btn btn-warning btn-block" value="Voir mon panier">';
                        echo '</form>';
                        ?>
                    </div>
                </section>
            </div>
        </div>
        <div class="col-lg-12 mt-4">
            <h4>
                Si vous souhaitez me contacter voici mes coordonnées : <br> Adresse email : <a href="mailto:<?php echo $mailclient; ?>"><?php echo $mailclient; ?> </a> - N° de téléphone mobile : <?php echo wordwrap($telclient, 2, ' ', true); ?> <br> <br> Et celles de <?php echo $prenomconjoint; ?> <?php echo $nomconjoint; ?> : <br> Adresse email : <a href="mailto:<?php echo $mailconjoint; ?>"><?php echo $mailconjoint; ?> </a> - N° de téléphone mobile : <?php echo wordwrap($telconjoint, 2, ' ', true); ?>
            </h4>
        </div>
    </div>
</div>
</div>

<?php require_once('../partials/_footer.php'); ?>


Fichier "addpanier.php"

<?php require_once('ajout.php'); ?>

<?php

$json = array('error' => true);
if (isset($_GET['ProduitID'])) {
    $ProduitID = ($_GET['ProduitID']);
    $produit = $DB->query('SELECT * FROM produit WHERE ProduitID=:ProduitID', array('ProduitID' => $_GET['ProduitID']));
    if (empty($produit)) {
        $json['message'] = "Ce produit n'existe pas";
    }
    $panier->add($produit[0]->ProduitID);
    $json['error'] = false;
    $json['message'] = 'Le produit a bien été ajouté à votre panier';
} else {
    $json['message'] = "Vous n'avez pas selectionné de produit à ajouter au panier";
}
echo json_encode($json);


Fichier "1_panier.php" qui ne fonctionne pas en ligne mais en localhost sans problème.

<?php include "ajout.php";

echo '<pre>';
print_r($_GET);
echo '</pre>';

if (!empty($_GET['prenomclient']) && ($_GET['nomclient'])) {
    $prenomclient = ($_GET['prenomclient']);
    $nomclient = ($_GET['nomclient']);

    $statement = $bdd->prepare("SELECT * FROM client WHERE nomclient = ?");
    $statement->execute(array($nomclient));
    $item = $statement->fetch();
    $codeagence         = $item['codeagence'];
    $prenomclient       = $item['prenomclient'];
    $mailclient         = $item['mailclient'];
    $telclient          = $item['telclient'];
    $nomclient          = $item['nomclient'];
    $prenomconjoint     = $item['prenomconjoint'];
    $nomconjoint        = $item['nomconjoint'];
    $mailconjoint       = $item['mailconjoint'];
    $telconjoint        = $item['telconjoint'];
    $nomevenement       = $item['nomevenement'];
}

if (isset($_GET['del'])) {
    $panier->del($_GET['del']);
}

if (!empty($_GET['ProduitID'])) {
    $ProduitID = ($_GET['ProduitID']);
}

?>

<div class="container">
    <div class="row">
        <div class="col-lg-12 pb-4 text-justify">
            <h1 class="rounded mt-2 pt-4 pb-4 text-center btn-primary">Panier de mes dons en faveur de <br>
                <strong><?php echo $prenomclient . " " . $nomclient . " et " . $prenomconjoint . " " . $nomconjoint  ?></strong>
            </h1>
            <br>
            <form method="post" action="">
                <div class="row">
                    <?php
                    $ids = array_keys($_SESSION['panier']);
                    if (empty($ids)) {
                        $produits = array();
                    } else {
                        $produits = $DB->query('SELECT * FROM produit WHERE ProduitID IN (' . implode(',', $ids) . ')');
                    }
                    foreach ($produits as $produit) :
                        // session_destroy();
                    ?>
                        <div class="col-sm-4 mb-3">
                            <div class="card">
                                <img class="card-img-top" src="../img/produits/<?= $produit->imgproduit; ?>" alt="Produit liste cadeau Onelist">
                                <div class="card-header"><b> <?= $produit->nomproduit; ?> </b></div>
                                <div class="card-body">
                                    <class="card-title"><?= $produit->nomtheme; ?><br>
                                        <class="card-text"><?= $produit->nomvoyage; ?></br>
                                            Prix du produit = <?= $produit->prixproduit; ?>€ <br>
                                            <div class="form-group row">
                                                <label for="quantite" class="col-auto col-form-label">Quantité = </label>
                                                <div class="col">
                                                    <input class="form-control" type="text" name="panier[quantite][<?= $produit->ProduitID; ?>]" value="<?= $_SESSION['panier'][$produit->ProduitID]; ?>">

                                                </div>
                                            </div>
                                </div>
                                <div class="card-footer">
                                    <a href="1_panier.php?delPanier=<?= $produit->ProduitID . '&prenomclient=' . $prenomclient . '&nomclient=' . $nomclient; ?>  ">Supprimer du panier</a>
                                </div>
                            </div>
                        </div>
                    <?php endforeach; ?>
                </div>

                <div class="col-lg-12 alert btn-success mb-4 text-center">
                    <h5>Le montant total de mon don est de : <b><?= $prixtotal = $panier->total(); ?> €</b> </h5>
                    <p class="card-text  ">
                        Ce montant sera débité sur ma carte de crédit après avoir cliqué sur <i>Je confirme mon don</i>
                    </p>
                </div>
                <!-- </div> -->
                <div class="row">
                    <div class="col-lg-12">
                        <table class="table table-borderless center">
                            <tr>
                                <td>
                                    <button class="btn btn-success" type="button"><a style="color:#fff" href="<?php echo '1_payment.php?prixtotal='.$prixtotal.'&prenomclient=' . $prenomclient . '&nomclient=' . $nomclient  ?>">Je confirme mon achat</a></button>
                                </td>
                                <td>
                                    <button class="btn btn-success" type="button"><a style="color:#fff" href="<?php echo '1_espace_donateur.php?prenomclient=' . $prenomclient . '&nomclient=' . $nomclient  ?>">Retour à la liste des produits</a></button>
                                </td>
                                <td>
                                    <button class="btn btn-success" type="button" onClick="window.location.reload();">Mise à jour du panier</button>
                                </td>
                                <td>
                                    <button class="btn btn-success" type="submit">recalculer</button>
                                </td>
                                <td>
                                    <a href="logout.php"><span class="btn btn-danger "> J'annule mon don</span></a></button>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<?php require('../partials/_footer.php'); ?>


D'avance mille mercis de votre aide.
Cordialement +++
Modérateur
Bonjour,

Va falloir apprendre à débogguer ! Smiley lol

1) C'est quoi le symptôme quand "il ne marche pas" ? Page blanche ? Page non trouvée ? Autre chose ?
2) Si on ne met que print_r($_GET); dans "1_panier.php", est-ce qu'il marche ?
3) Attention aux majuscules/minuscules dans les noms de fichiers et de dossiers.
4) Est-ce qu'un select tout simple sur la base marche ?

Amicalement,
Bonsoir,

C'est vrai que je n'ai pas l'habitude de débogguer, merci de me mettre sur la voie :

1°) Ca ne marche pas c'est à dire que lorsque je cliques sur le bouton "Ajouter au panier" la page "1_panier.php" s'ouvre bien, mais mon panier est vide., alors qu'en local, s'affichent bien les sélections que j'ai faites sur la page "1_espace_donateur.php"
2°) Oui, print_r ($_GET) m'affiche les bonnes données envoyées par la page "espace_donateur.php"
3°) Oui, tous les noms de fichiers sont corrects, maj et min vérifiés.
4°) Oui, le select fonctionne sur la page "1_panier.php" exemple, lorsque je fais un print_r de $item après mon select, toutes mes données s'affichent. Exemple :

if (!empty($_GET['prenomclient']) && ($_GET['nomclient'])) {
    $prenomclient = ($_GET['prenomclient']);
    $nomclient = ($_GET['nomclient']);

    $statement = $bdd->prepare("SELECT * FROM client WHERE nomclient = ?");
    $statement->execute(array($nomclient));
    $item = $statement->fetch();
    $codeagence         = $item['codeagence'];
    $prenomclient       = $item['prenomclient'];
    $mailclient         = $item['mailclient'];
    $telclient          = $item['telclient'];
    $nomclient          = $item['nomclient'];
    $prenomconjoint     = $item['prenomconjoint'];
    $nomconjoint        = $item['nomconjoint'];
    $mailconjoint       = $item['mailconjoint'];
    $telconjoint        = $item['telconjoint'];
    $nomevenement       = $item['nomevenement'];
}

echo '<pre>';
print_r($item);
echo '</pre>';


Voilà ce que ça donne :

Array
(
    [ClientID] => 48
    [0] => 48
    [codeagence] => GEO51100
    [1] => GEO51100
    [nomagence] => Géovision
    [2] => Géovision
    [prenomclient] => François
    [3] => François
    [nomclient] => HOLLANDE
    [4] => HOLLANDE
    [dateevenement] => 01/05/2022
    [5] => 01/05/2022
    [nomevenement] => Départ en retraite
    [6] => Départ en retraite
    [nomvoyage] => Séjour Marrakech
    [7] => Séjour Marrakech
    [telclient] => 0651824402
    [8] => 0651824402
    [mailclient] => f.hollande@gmail.com
    [9] => f.hollande@gmail.com
    [adresseclient] => 40 rue des peupliers
    [10] => 40 rue des peupliers
    [cpclient] => 19000
    [11] => 19000
    [villeclient] => TULLE
    [12] => TULLE
    [prenomconjoint] => Julie
    [13] => Julie
    [nomconjoint] => GAYET
    [14] => GAYET
    [telconjoint] => 0322556644
    [15] => 0322556644
    [mailconjoint] => j.gayet@free.fr
    [16] => j.gayet@free.fr
    [imgclient] => couple2.jpg
    [17] => couple2.jpg
    [message] => Message                                                
    [18] => Message                                                
    [pwdclient] => 1111
    [19] => 1111
)

Edit: mise en page modifiée par parsimonhi
Modifié par parsimonhi (25 Jan 2022 - 23:29)
Modérateur
Bonjour,

1) Elle vient d'où la variable $panier qui est dans le fichier "1_panier.php" ?
2) Les () autour de $_GET['xxx'] ne servent à rien (mais ce n'est pas ça qui empêche le code de fonctionner).

Amicalement,
Modérateur
« Si tu donnes un poisson à un homme, il mangera un jour, si tu lui apprends à pêcher, il mangera toujours » Smiley jap
1°) La variable $panier vient de la page addpanier.php comme suit :

<?php session_start(); ?>


<?php
require_once('../fonctions/panier.class.php');
require_once('../fonctions/db.class.php');
$DB = new DB();
$panier = new panier($DB);
?>

<?php

$json = array('error' => true);
if (isset($_GET['ProduitID'])) {
    $ProduitID = ($_GET['ProduitID']);
    $produit = $DB->query('SELECT * FROM produit WHERE ProduitID=:ProduitID', array('ProduitID' => $_GET['ProduitID']));
    if (empty($produit)) {
        $json['message'] = "Ce produit n'existe pas";
    }
    $panier->add($produit[0]->ProduitID);
    $json['error'] = false;
    $json['message'] = 'Le produit a bien été ajouté à votre panier';
} else {
    $json['message'] = "Vous n'avez pas selectionné de produit à ajouter au panier";
}
echo json_encode($json);


2°) C'est vrai, tu m'avais déjà dit lors d'un autre échange que les () entre les $_GET ne servent à rien. Je n'ai pas encore pris le temps de modifier cela sur mes pages.
Modérateur
Bonjour,

Oui, mais comment se retrouve-t-elle dans le fichier "1_panier.php" ? Si elle est déclarée dans "addpanier.php", elle est inconnue dans "1_panier.php" me semble-t-il.

Amicalement,
Bonjour,
Je me suis absenté quelques semaines et je viens de me rendre compte que j'ai complètement oublié de passer ce sujet en résolu.
Depuis tout fonctionne.
Mille mercis de votre aide, excellent WE.
Cordialement +++