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 :

[Sécurité] suppression d'article dans un panier


Sujet :

Langage PHP

  1. #1
    Membre confirmé Avatar de oceane751
    Profil pro
    Intégrateur Web
    Inscrit en
    Novembre 2004
    Messages
    1 280
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Intégrateur Web

    Informations forums :
    Inscription : Novembre 2004
    Messages : 1 280
    Points : 575
    Points
    575
    Par défaut [Sécurité] suppression d'article dans un panier
    bonsoir!

    voilà j'aimerais supprimer des articles dans mon panier

    voici le code de mon panier :
    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
     
    <?
     
    include ("definitioninfo.php");
    include ("aff_panier.inc.php");
     
    if (!session_id())
     session_start();
     
     
     
    if (!isset($_SESSION['panier']))    //$panier pas defini              //sert pour la gestion du panier
    {                                                           //ne pas tenir compte pr le moment
     $panier = array (
      "ref_produit" => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23),
      "quantite"  => array (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
     );
     $_SESSION['panier'] = $panier;
     $_SESSION['total'] = 0;
      }
     
    session_register('article');
    session_register('prix');
    session_register('quantite');
    session_register('ref_produit');
    //$_POST['quantite']= $_SESSION['quantite'];
     // $_POST['article'] = $_SESSION['article'];
     
    for ($i = 0; $i < 23; $i++)                                          //pr le panier
    {
     //echo("article : ".$_SESSION['panier']['ref_produit'][$i]);
     //echo(" quantite : ".$_SESSION['panier']['quantite'][$i]."<br>");
    }
     
     
    $quantite = $_POST['quantite'];
    $article = $_POST['article'];
    ///echo "quantite post = ".$quantite;
     
     
     
     
    if(!($base=mysql_connect("localhost","root","pouet")))
    {
     echo "<br><B>probleme lors de la connexion à MySql</B><br>";
     exit();
    }
    else
    {
     mysql_select_db(BASE, $base);
     if (($tab_com = mysql_query("SELECT ref_produit, designation_produit, prix_produit
                   	 	      FROM produit
            		      WHERE designation_produit = '".$article."'", $base)))
    $res_com = mysql_fetch_array($tab_com);   //tableau contenant les valeurs de la requete (resultat_commande)
    }
     
    $_SESSION['article'] = $res_com[1];
    $_SESSION['prix'] = $res_com[2];
    $_SESSION['quantite'] = $quantite;
    $_SESSION['ref_produit']= $res_com[0];
     
    //$_SESSION['panier']['quantite'][$_SESSION['ref_produit']]++;            //pr le panier
    $_SESSION['panier']['quantite'][$_SESSION['ref_produit']] = $_SESSION['panier']['quantite'][$_SESSION['ref_produit']]+$quantite;
     
    $_SESSION['total'] = $_SESSION['total']+($res_com[2]*$quantite);
    //$_SESSION['TTC'] = $_SESSION['total']+ $_SESSION['total']*(19.6/100); // à aligner a droite
     
    echo "<html>
    <head>
    <title>Bienvenue sur materiel-informatique.fr</title></head>
    <body bgcolor=#99ff99  align=right>
    <h1 align=\"center\"><font size=+6><font color=\"#000000\"><u>Votre Panier de Commande :</u></font></font></h1>
    <br>
    <p><form method = \"POST\" action=\"http://127.0.0.1/oceanecoin/SITE%20INFO/ordinateur%20de%20bureau.php\"><input type='submit' value='<<<<<< poursuivre mes achats'></form></p>
    <table border=\"1\">
    <align=\"center\">
    
     <tr>
    
     <td><b><center>Reference </b></td><br>
      <td><b><center>Article</b></td><br>
      <td><b><center>Prix Unitaire</b></td>
      <td><b><center>Quantité</b></td>
      <td><b><center>Montant</b></td>
    
    
      <td><b><center><img src ='http://xx/yy/SITE%20INFO/corbeille.gif'></td>
    
    
     </tr>";
     //<a href='supprime.php'=$_SESSION['panier']['ref_produit'][$i]>'supprimer'</a>
     
    aff_panier(); //fonction de gestion du panier
    /*echo " <tr  align=\"center\">
      <td><b>".$res_com[1]."</b></td>
      <td><b>".$res_com[2]."</b></td>
      <td><b>".$quantite."</b></td>
      <td><b>".$res_com[2]*$quantite." €</b></td>
     </tr>";*/
     
     echo "<tr><td></td><td></td><td><b><center>Total  : </b></td><td align = \"center\"><b>".$_SESSION['total']."€</b></td></tr>";
     //echo "<tr><td></td><td></td><td><b><center>TVA : </b></td><td align = \"right\"><b>".$_SESSION['total']*(19.6/100)."€</b></td></tr>";
     //echo "<tr><td></td><td></td><td><b><h3><center>TOTAL TTC : </b></td><td align = \"right\"><h3><u><b>".$_SESSION['TTC']."€</b></td></tr>";    //sert pour le panier
     //echo "<tr><td></td><td></td><td><b><u>TOTAL :</u></b></td><td align = \"right\"><b>".$res_com[2]*$quantite." €</b></td></tr>
     echo "<tr><td></td><td></td><td></td><td colspan='1'><form method = \"POST\" action=\"http://xx/yy/boutiqueinfo/commande2info.php\"><input type='submit' value='Terminer votre Commande'></td></tr>
    
     </table>
    </form>
    </body>
    </html>"
    ?>

    et voici le code de "aff_panier.inc.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
     
     
    <?                            //sert pour le panier
                                     //contient des fonctions utiles
    if (!session_id())
     session_start();
     
    function aff_panier()
    {
     for ($i = 1; $i <= 23 ; $i++)
     {
      //echo("article : ".$_SESSION['panier']['ref_produit'][$i]);
      //echo(" quantite : ".$_SESSION['panier']['quantite'][$i]."<br>");
     //echo('<a href="http://xx/yy/supprime.php='.$_SESSION['panier']['ref_produit'][$i]);
     //echo ('">Supprimer</a>');
     }
     
     
     if(!($base=mysql_connect("localhost","root","pouet")))
     {
      echo "<br><B>probleme lors de la connexion à MySql</B><br>";
      exit();
     }
     else
     {
      mysql_select_db(BASE, $base);
      for ($i = 1; $i <= 23 ; $i++)
      {
       if (($tab_com = mysql_query("SELECT ref_produit, designation_produit, prix_produit
                   	 	      FROM produit
            		      WHERE ref_produit = '".$_SESSION['panier']['ref_produit'][$i]."'
                                  AND '".$_SESSION['panier']['quantite'][$i]."' > 0", $base)))
     
        $res_com = mysql_fetch_array($tab_com);   //tableau contenant les valeurs de la requete (resultat_commande)
      //print_r ($res_com);
     
      // si envoi de formulaire 
    if(isset($_POST['sub_form'])) {
     
       // si suppression 
       if($_POST['sub_form']=="supprimer") { 
     
          $sql = "DELETE FROM produit WHERE ref_produit = '".$_SESSION['panier']['ref_produit']."'";
          $res = mysql_query($sql) or die (mysql_error());
     
      }
      }
     
      $quantite = $_SESSION['panier']['quantite'][$i];
      $prix = $res_com[2]*$quantite;
     
      if ($quantite > 0)
      {
       echo " <tr  align=\"center\">
       <td><b>".$res_com[0]."</b></td>
       <td><b>".$res_com[1]."</b></td>
       <td><b>".$res_com[2]."</b></td>
       <td><b>".$quantite."</b></td>
       <td><b>".$prix." €</b></td>
       <td></td>
    <td><input type = 'submit' name = 'sub_form' value = 'supprimer'></td>
    
    
    </tr>";
     
     
      }
      }
     }
     
     
    }
     
    //<form method= POST action = 'supprime.php'>
     
    //<input type=hidden name= retirer  value= RETIRER >
    //<input type= hidden name= article  value= "echo $row['article']">
    //</form>
      //<input type=submit value=cliquez ici>
     
      //onClick='alert(\"voullez vous vraiment supprimer?\")'>
    ?>

    merci pour votre aide...

  2. #2
    Expert éminent Avatar de Mr N.
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    5 418
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 5 418
    Points : 6 449
    Points
    6 449
    Par défaut


    Quel est la question ?

  3. #3
    Membre averti Avatar de ShinJava
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    413
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 413
    Points : 357
    Points
    357
    Par défaut
    Apparement il aimerait supprimer une article de son panier.
    Donc d'apres ce que j'ai compris, tes elements de ton panier sont stocké dans un tableau.
    Pour pouvoir supprimer un element de ton tableau, tu peux utiliser array_splice. Par exemple :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    array_splice($Panier, $numero_de_la_ligne_a_retirer, 1);
    Si tu veux retirer la ligne 2 par exemple (Tab[2])
    Tu fais :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    array_splice($Panier, 2, 1);
    J'espere que ca pourra t'aider.

    ++
    ShinJava

  4. #4
    Membre confirmé Avatar de oceane751
    Profil pro
    Intégrateur Web
    Inscrit en
    Novembre 2004
    Messages
    1 280
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Intégrateur Web

    Informations forums :
    Inscription : Novembre 2004
    Messages : 1 280
    Points : 575
    Points
    575
    Par défaut
    merci pour vos réponses
    j'avoue que je n'ais pas assez expliquer mon problème
    en faite, j'aimerais pouvoir supprimer des articles dans mon panier (eventuellement avec une liste deroulante permettant de supprimer 1, 2 ... quantité d'un même article ce qui serait certainement plus judicieux)

Discussions similaires

  1. Réponses: 12
    Dernier message: 17/06/2008, 10h49
  2. Ajout d'un article dans un panier
    Par spawns dans le forum Langage
    Réponses: 5
    Dernier message: 03/02/2008, 23h58
  3. [eCommerce] Suppression de produit dans un panier
    Par sayes1 dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 6
    Dernier message: 29/01/2008, 22h17
  4. Recherche classe pour ajout/modif/suppression d'articles dans une base de donnée
    Par will89 dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 02/02/2007, 11h59
  5. nombre d'article dans mon panier
    Par sam01 dans le forum Langage
    Réponses: 1
    Dernier message: 26/07/2006, 19h50

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