IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Notice: Undefined variable lors de la création d'un panier


Sujet :

Langage PHP

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Juin 2009
    Messages
    4
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Juin 2009
    Messages : 4
    Points : 2
    Points
    2
    Par défaut Notice: Undefined variable lors de la création d'un panier
    Bonjour developpeur php ,

    Toujours en lien avec ce fameux panier en ligne : http://jcrozier.developpez.com/articles/web/panier/

    voici le contenu de la page panier.php:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    <?php
    session_start();
    include_once("fonctions-panier.php");
     
     
    if (isset($_GET['action']))
    {
    $erreur=false;
     if(in_array( $_GET['action'],array('ajout', 'suppression', 'refresh')))
      $action = $_GET['action'];
     else
      $erreur=true;
     
     $l = preg_replace('#\v#', '', $_GET['l']);
     
     $q = intval($_GET['q']);
     
     $p = floatval($_GET['p']);
     
    }
     
    elseif(isset($_POST['action']))
    {
     unset($_GET);
     $erreur=false;
     
     if(in_array($_POST['action'],array('ajout', 'suppression', 'refresh')))
      $action=$_POST['action'];
     else
      $erreur=true;
     
      $l = preg_replace('#\v#', '',$_POST['l']);
     
      $p = floatval($_POST['p']);
     
     
     $QteArticle = array();
     
     $i=0;
     foreach ($_POST['QteArticle'] as $contenu){
      $QteArticle[$i++] = intval($contenu);
     
     }
     
    }
     
     
     
     
    if ($erreur==false){
     
     switch($action){
     
      Case "ajout":
      ajouterArticle($l,$q,$p);
      break;
     
      Case "suppression":
      supprimerArticle($l);
      break;
     
      Case "refresh" :
     
      for ($i = 0 ; $i < count($QteArticle) ; $i++)
      {
        modifierQTeArticle($_SESSION['panier']['libelleProduit'][$i],round($QteArticle[$i]));
      }
      break;
     
      Default:
      break;
     
     }
    }
     
    echo '<?xml version="1.0" encoding="iso-8859-1"?>';?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr"> 
    <head>
    <title>LE PANIER</title>
    </head>
    <body>
     
    <form method="post" action="panier.php">
    <table style="width: 400px">
    <tr>
          <td colspan="4">PANIER APPLICATION</td >
    </tr>
    <tr>
          <td>Libellé</td>
          <td>Quantité</td>
          <td>Prix Unitaire</td>
          <td>Action</td>
    </tr>
     
     
    <?php
    if (creationPanier())
    {
    $nbArticles=count($_SESSION['panier']['libelleProduit']);
      if ($nbArticles <= 0)
       echo "<tr><td>Votre panier est vide </ td></tr>";
      else
      {
       for ($i=0 ;$i < $nbArticles ; $i++)
       {
        echo "<tr>";
        echo "<td>".htmlspecialchars($_SESSION['panier']['libelleProduit'][$i])."</ td>";
        echo "<td><input type=\"text\" size=\"4\" name=\"QteArticle[]\" value=\"".htmlspecialchars($_SESSION['panier']['qteProduit'][$i])."\"/></td>";
        echo "<td>".htmlspecialchars($_SESSION['panier']['prixProduit'][$i])."</td>";
        echo "<td><a href=\"".htmlspecialchars("panier.php?action=suppression&l=".rawurlencode($_SESSION['panier']['libelleProduit'][$i]))."\">XX</a></td>";
        echo "</tr>";
       }
     
      echo "<tr><td colspan=\"2\"> </td>";
      echo "<td colspan=\"2\">";
      echo "Total : ".MontantGlobal();
      echo "</td></tr>";
     
      echo "<tr><td colspan=\"4\">";
      echo "<input type=\"submit\" value=\"Rafraichir\"/>";
      echo "<input type=\"hidden\" name=\"action\" value=\"refresh\"/>";
     
      echo "</td></tr>";
      }
    }
    ?>
    </table>
    </form>
    </body>
    </html>


    Au tour de la page des fonctions du panier, voici le contenu de fonctions-panier.php


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    <?php
     
    function creationPanier(){
    $ret=false;
     
    if (isset( $_SESSION['panier']))
     $ret = true;
    else
    {
     
      $_SESSION['panier']=array();
      $_SESSION['panier']['libelleProduit'] = array();
      $_SESSION['panier']['qteProduit'] = array();      
      $_SESSION['panier']['prixProduit'] = array();
      $ret=true;
    }
    return $ret;
     
    }
     
     
     
     
    function ajouterArticle($libelleProduit,$qteProduit,$prixProduit){
     
    if (creationPanier())
    {
    $positionProduit = array_search($libelleProduit,  $_SESSION['panier']['libelleProduit']);
     
      if ($positionProduit !== false)
      {
       $_SESSION['panier']['qteProduit'][$positionProduit] += $qteProduit ;
      }
      else
      {
       array_push( $_SESSION['panier']['libelleProduit'],$libelleProduit);
       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.";
    }
     
     
     
     
     
    function supprimerArticle($libelleProduit){
     
    if (creationPanier())
    {
      $tmp=array();
      $tmp['libelleProduit'] = array();
      $tmp['qteProduit'] = array();      
      $tmp['prixProduit'] = array();
     
      for($i = 0; $i < count($_SESSION['panier']['libelleProduit']); $i++) 
      {
       if ($_SESSION['panier']['libelleProduit'][$i] !== $libelleProduit)
       {
        array_push( $tmp['libelleProduit'],$_SESSION['panier']['libelleProduit'][$i]);
        array_push( $tmp['qteProduit'],$_SESSION['panier']['qteProduit'][$i]); 
        array_push( $tmp['prixProduit'],$_SESSION['panier']['prixProduit'][$i]);
       }
     
      }
     
     
    $_SESSION['panier'] =  $tmp;
    unset($tmp);      
     
    }
    else
      echo "Un problème est survenu veuillez contacter l'administrateur du site.";
    }
     
     
     
     
     
     
     
    function modifierQTeArticle($libelleProduit,$qteProduit){
    if (creationPanier())
    {
     
      if ($qteProduit > 0)
      {
       $positionProduit = array_search($libelleProduit,  $_SESSION['panier']['libelleProduit']);
     
       if ($positionProduit !== false)
       {
        $_SESSION['panier']['qteProduit'][$positionProduit] = $qteProduit ;
       }
      }
      else
       supprimerArticle($libelleProduit);
     
    }
    else
      echo "Un problème est survenu veuillez contacter l'administrateur du site.";
    }
     
     
     
     
     
     
    function MontantGlobal(){
     
    $total=0;
     
      for($i = 0; $i < count($_SESSION['panier']['libelleProduit']); $i++) 
      {            
       $total += $_SESSION['panier']['qteProduit'][$i] * $_SESSION['panier']['prixProduit'][$i]; 
      }
     
    return $total;
    }
     
     
     
    ?>

    Je pense que le contenu est bon, mais comment creer le catalogue de produit sur la base de donnée Mysql.

    les erreurs de la page sont les suivantes pour panier.php

    Notice: Undefined variable: erreur in C:\Program Files\EasyPHP 2.0b1\www\panier.php on line 51

    Notice: Undefined variable: action in C:\Program Files\EasyPHP 2.0b1\www\panier.php on line 55

    Notice: Undefined variable: action in C:\Program Files\EasyPHP 2.0b1\www\panier.php on line 59

    Notice: Undefined variable: action in C:\Program Files\EasyPHP 2.0b1\www\panier.php on line 63
    Aidez moi s'il vous plait

  2. #2
    Inactif
    Inscrit en
    Octobre 2008
    Messages
    826
    Détails du profil
    Informations forums :
    Inscription : Octobre 2008
    Messages : 826
    Points : 172
    Points
    172
    Par défaut
    C'est assez simple, il faut que créé ses variable ;

    erreur et action dans fonctions-panier.php

    Car elle n'existe pas.

  3. #3
    Candidat au Club
    Profil pro
    Inscrit en
    Juin 2009
    Messages
    4
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Juin 2009
    Messages : 4
    Points : 2
    Points
    2
    Par défaut
    Ok

    Merci de ta reponse, je commencais à me dire que c'etait DIE.

Discussions similaires

  1. [MySQL] Notice: Undefined variable: prenom in c:\documents and settings\stagiaire10\mes docum
    Par fofina dans le forum PHP & Base de données
    Réponses: 6
    Dernier message: 15/10/2007, 00h18
  2. Notice: Undefined variable: id in
    Par dynam dans le forum SQL Procédural
    Réponses: 1
    Dernier message: 11/09/2007, 17h12
  3. Notice: Undefined variable
    Par oranoutan dans le forum Langage
    Réponses: 19
    Dernier message: 21/12/2005, 22h28
  4. Notice: Undefined variable
    Par kayn dans le forum Langage
    Réponses: 2
    Dernier message: 03/10/2005, 20h44
  5. Réponses: 3
    Dernier message: 22/09/2005, 11h24

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo