Pb suppression article dans un panier

justine75 Messages postés 49 Date d'inscription samedi 21 mai 2005 Statut Membre Dernière intervention 29 décembre 2005 - 2 déc. 2005 à 23:05
justine75 Messages postés 49 Date d'inscription samedi 21 mai 2005 Statut Membre Dernière intervention 29 décembre 2005 - 3 déc. 2005 à 16:24
bonsoir!


voilà j'aimerais supprimer des articles dans mon panier


voici le code de mon panier :
<?


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]."
");
}



$quantite = $_POST['quantite'];
$article = $_POST['article'];
///echo "quantite post = ".$quantite;



if(!($base=mysql_connect("localhost","root","pouet")))
{
 echo "
 probleme lors de la connexion &#224; MySql 
";
 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); // &#224; aligner a droite


echo "<html>
<head>
<title>Bienvenue sur materiel-informatique.fr</title></head>

Votre Panier de Commande :

<form method = "POST" action="[Supprimer');
 }



 if(!($base=mysql_connect("localhost","root","pouet")))
 {
  echo "
 probleme lors de la connexion &#224; MySql 
";
  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> ".$res_com[0]." </td>
   <td>".$res_com[1]."</td>
   <td>".$res_com[2]."</td>
   <td>".$quantite."</td>
   <td>".$prix." ?</td>
   <td></td>
<td></td>



</tr>";



  }
  }
 }



}


//<form method POST action 'supprime.php'>


//
//
//</form>
  //


  //onClick='alert("voullez vous vraiment supprimer?")'>
?>






merci pour votre aide...

3 réponses

FhX Messages postés 2350 Date d'inscription mercredi 13 octobre 2004 Statut Membre Dernière intervention 18 avril 2015 3
2 déc. 2005 à 23:18
Ajouter un article :
if ( !isset($_SESSION['article']) ) {
$_SESSION['article'] = "valeur";
}

Supprimer un article :
if ( isset($_SESSION['article']) ) {
unset($_SESSION['article']);
}

Voila voila :)
0
coucou747 Messages postés 12303 Date d'inscription mardi 10 février 2004 Statut Membre Dernière intervention 30 juillet 2012 44
3 déc. 2005 à 10:12
salut

mais quel code crade !

tu pourrais pas commencer par produire un truc lisible avant de poster ???



$sql "DELETE FROM produit WHERE ref_produit '".$_SESSION['panier']['ref_produit']."'";



devrait être :



$sql 'DELETE FROM produit WHERE ref_produit'.$_SESSION['panier']['ref_produit'];


regarde ce lien :

http://coucou747.hopto.org/index.php?action=lire_page&id=4&mois=11-2005

il t'expliquera pas mal de choses sur la programmation...


In a dream, I saw me, drop dead... U was here, U cried... It was just a deam, if I die, U won't cry, maybe, U'll be happy

http://coucou747.hopto.org
0
justine75 Messages postés 49 Date d'inscription samedi 21 mai 2005 Statut Membre Dernière intervention 29 décembre 2005
3 déc. 2005 à 16:24
merci pour vos réponses

j'ai testé le bout de code proposé par fhX




if(isset($_POST['sub_form'])) {


   // si suppression 
   if($_POST['sub_form']=="supprimer") {
       if ( isset($_SESSION['panier']['ref_produit'][$i]) ) {
     unset($_SESSION['panier']['ref_produit'][$i]);
}
 }
  }

mais il ne se passe rien...
0
Rejoignez-nous