Bonjour j'au un problême de suppression avec mon vadie virtuel
voilà comment il marche
une page catalogue ou mes articles sont affichés:
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| <?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<link rel="stylesheet" media="screen" type="text/css" title="Design" href="design.css" />
<title>Catalogue de produits</title>
</head>
<body>
<?php
mysql_connect("localhost","root","");
mysql_select_db("ecommerce");
$reponse=mysql_query("SELECT * FROM produits");
while ($donnees = mysql_fetch_array($reponse) ) // On fait une boucle pour lister tout ce que contient la table :
{?><div id="listeproduits"><?php
echo $donnees['nom'];
?><a href="ficheproduit.php?id=<?php echo $donnees['id'];?>"><img src="upload/<?php echo $donnees['photomin'];?>" class="img" alt="Détails produit" /></a></div><?php // on affiche tout
}
?>
</body>
</html> |
cette page renvoi sur la fiche article quand on clique sur l'article:
quant on cliques sur acheter,deux varaiables deux $_GET sont transmis=>le sens (ajout ou suppression de l'article du panier) et l'id de l'article
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| <?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<link rel="stylesheet" media="screen" type="text/css" title="Design" href="design.css" />
<title>Fiche produit</title>
</head>
<body>
<?php
extract($_GET);
mysql_connect("localhost","root","");
mysql_select_db("ecommerce");
$reponse=mysql_query("SELECT * FROM produits WHERE id='".addslashes($id)."'"); //connexion puis recherche des infos articles
$donnees = mysql_fetch_array($reponse);
echo $donnees['nom']; ?> coute <?php echo $donnees['prix'];?> euros et yen a <?php echo $donnees['quant'];
?><br><a href="ajoutpanier.php?id=<?php echo $donnees['id'];?>&sens=ajout">Acheter <?php echo $donnees['nom'];?></a><br><a href="catalogue.php"> Revenir au catalogue</a><br>
<div style="width: 350px; height: 350px; border: 1px solid black;"><img src="upload/<?php echo $donnees['photo'];?>" /></div><?php //on liste le tout dans une boucle à laquelle on a incorporé un div
mysql_close();
?>
</body>
</html> |
ensuite mes $_GET sont utilisés sur la page ou l'article est ajouté au panier:
Code :
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
| <?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<link rel="stylesheet" media="screen" type="text/css" title="Design" href="design.css" />
<title>Ajout de l'article choisi au panier</title>
</head>
<body>
<?php
extract($_GET);
mysql_connect("localhost","root",""); // connexion
mysql_select_db("ecommerce");
$reponse=mysql_query("SELECT * FROM produits WHERE id='".addslashes($id)."'"); // recup des infos sur l'article
$donnees = mysql_fetch_array($reponse);
$nom=$donnees['nom'];
$prix=$donnees['prix'];
if (isset($nom)) //donc si il existe un article
{
if($sens=="ajout") // et que on veut ajouter
{
$_SESSION['achats'][] = array ("nom" => $nom,"prix" => $prix);
echo "vous avez ajouté l'article à votre panier"; // on mets tout çà en session tableau
}
}
?><br><a href="lepanier.php">aller au panier</a><?php
mysql_close();
?>
</body> |
donc là l'article est rajouté,le script est commenté ...
et ensuite on a ma page panier ou on pourra effectuer des opération sur le panier
la voici:
Code :
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
| <?php
session_start();
print_r($_SESSION['achats']);?><br><?php
mysql_connect("localhost","root","");
mysql_select_db("ecommerce");
for($i=0;$i<count($_SESSION['achats']);$i++) //on liste le panier à l'aide d'une boucle
{
$reponse=mysql_query("SELECT * FROM produits WHERE nom='".addslashes($_SESSION['achats'][$i]['nom'])."'");
$donnees = mysql_fetch_array($reponse);// ON récupère les infos articles pour mettre bien en forme dans un div
?><div style="width: 400px;height: 110px; border: 1px solid black;"><img src="upload/<?php echo $donnees['photomin'];?>" alt="Détails produit" /><?php echo $_SESSION['achats'][$i]['nom']." Prix =>".$_SESSION['achats'][$i]['prix'];?>€ <a href="lepanier.php?nomsup=<?php echo $_SESSION['achats'][$i]['nom'];?>">Supprimer</a>
</div><br><?php
$prixtotal+=$_SESSION['achats'][$i]['prix']; // calcul du prix total
}
if(isset($_GET['nomsup'])) //si jamais on est issu d'un rafraissisement en vue d'une suppression d'article ben on le supprime
{
extract($_GET);?><br><?php
for($i=0;$i<count($_SESSION['achats']);$i++) //on liste notre panier
{
if($_SESSION['achats'][$i]['nom']!==$nomsup)// et tout ce qui n'est pas l'article qu'on veut supprimer
{
$tmp[] = array ("nom" =>$_SESSION['achats'][$i]['nom'],"prix" =>$_SESSION['achats'][$i]['prix']); //on le mets dans un panier temporaire
}
}
$_SESSION['achats']=$tmp; // notre ancien panier temporaire devient notre véritable panier
}
echo "<br>Votre panier contient ".count($_SESSION['achats'])." articles pour un prix total de ".$prixtotal."€<br>";
?>
<a href="catalogue.php">aller au catalogue</a>
<br>
<a href="paiement.php">valider ma commande</a> |
le problême ici c'est que quand je supprimme un article,ma liste n'est pas mise à jour,il faut que je cliques deux fois sur supprimmer pour que l'article soit totalement supprimé de mon panier,c'est vraiment bizarre
donc si queulqu'un peut m'éclairer à ce sujet,son aide est la bienvenue...