Pour mon caddie, j'ai une page "boutique" ou je sélectionne ma photo à commander.
En appuyant sur la touche Commande je boucle sur cette page et j'affiche ma commande
Je mets la quantité désirée et j'appuie sur OK
J'arrive sur une page "commande" qui doit normalement servir unique de relais et me servir à prendre en compte ma commande ce qui n'est pas fait.
Normalement je met à jour mon caddie et donc je peux le voir sur une page "caddie" ce qui ne marche pas.
Je peux normalement modifier ou changer ma commande
J'ai l'impression que cela coince au niveau de la page "commande" mais je ne vois pas où.
Merci de me dire quel est le problème.
Voici mon code :
Page "Boutique" :
<?php
include ("connection.php");
session_start();//demarrage de la session
if(isset($_SESSION['panier']))//si il y a une commande dans le caddie alors on affiche un lien au caddie
{
echo "c'est bon";
echo"<div align='right'><a href='caddie.php'><b>VOIR CADDIE</b></a></div><br><br>";
}
?>
<H1 align="center">Votre Boutique en ligne ....</H1>
<table border="1" bgcolor="cccccc" align="center" width="75%">
<tr bgcolor='white'>
<td width="">Index_Photo</td>
<td width="">Prix</td>
<td width=""> </td>
</tr>
<?
if(!isset($_GET['prod']))// pas de variable dans l'url
{
$sql="Select * from tblphotos";
$req=mysql_query($sql)or exit ('Erreur dans le SQL !'.$sql.'<br>'.mysql_error());
while( $data=mysql_fetch_array($req) ) {
echo"<tr><td>".$data['Index_Photo']." </td><td> ".$data['Prixaveccadre']."</td><td> <a href='boutique.php?prod=".$data['Id']."'>Commande</a></td></tr>";
}
mysql_close();
?>
</table>
<?}
if(isset($_GET['prod'])){
if(!is_numeric($_GET['prod'])){//juste une première sécurité
echo"<font color='red'>MERCI DE NE PLUS RECOMMENCER CETTE OPERATION !!!</font>";
exit;
}
$sql1="Select* from tblphotos where Id=".$_GET['prod'];
$req1=mysql_query($sql1)or exit ('Erreur SQL !'.$sql1.'<br>'.mysql_error());
$nb=mysql_num_rows($req1);
if($nb==0){//juste une seconde sécurité
echo" <font color='red'>MERCI DE NE PLUS RECOMMENCER CETTE OPERATION !!!</font>";
exit;
}
//afichage du Produit séléctionné avec qté à commander à remplir:
while( $data=mysql_fetch_array($req1) ) {
?>
<form method="POST" action="commande.php">
<?
echo"<tr><td>".$data['Index_Photo']." </td><td colspan='2'> ".$data['Prixaveccadre']."</td></tr>".
"<tr><td colspan='3'align='center'>Quantité : <input type='text' name='qte' size='5'> <input type='submit' name='action' value='Commander'></td></tr>".
"<input name='id' type='hidden' value='".$data['Id']."'>";//trés important, en champ caché l'ID de la photo
}
mysql_close();
?>
</table><br>
<div align="center"><a href="javascript:history.go(-1)"><< Retour Boutique</a></div>
<?
}
?>
Page Commande<?
include ("connection.php");
session_start();
// nous allons enregistrer une commande
// nous vérifions que le bouton Commande a bien été déclanché:
if(isset($_POST['action']) and $_POST['action']=='Commander')
{
$id=$_POST['id'];id de la photo
$qte=$_POST['qte'];// quantité désirée par le client
if( empty($_SESSION['panier'][$id]) )//si le panier contenant cette fleur est vide
{
$_SESSION['panier'][$id]=$qte;// on enregistre la quantité désirée par le client
}
else // si le panier contient déjà cette photo
{
$_SESSION['panier'][$id]+=$qte;;// alors on ajoute la quantité à la valeur initiale
}
//on a terminé le traitement.
//on renvoie l'internaute sur la boutique.
<script="javascript">
location.replace("boutique.php");
</script>
}
//Nous allons supprimer une ou + ligne(s) de commande
if(isset($_POST['action']) and $_POST['action']=='Eliminer'){
if(empty($_POST['case']) )
{
?>
<script ="Javascript">
history.go(-1);
</script>
<?
exit;
}
foreach ($_POST['case'] as $delete){
unset($_SESSION['panier'][$delete]);
}//fin foreach
?>
<script ="Javascript">
location.replace('caddie.php');
</script>
<?
exit;
}
//fin delete
// nous allons changer une commande : Etape 1 ==> l'affichage
if(isset($_POST['action']) and $_POST['action']=='Changer'){
if(empty($_POST['case']) ){
?>
<script ="Javascript">
history.go(-1);
</script>
<?
exit;
}
?>
<form method="POST" action="">
<?
foreach($_POST['case'] as $modif){
$sql="Select * from tblphotos where Id='$modif'";
$req=mysql_query($sql)or exit ('Erreur SQL !'.$sql.'<br>'.mysql_error());
while( $data=mysql_fetch_array($req) ) {
echo"<b>Produit :</b> <i>".$data['Index_Photo']."</i><br>";
echo"<b>Quantité commandée :</b> <input type='text' name='exqte[$modif]' value='".$_SESSION['panier'][$modif]."' size='2'><hr>";
}//fin du while
}//fin du foreach
mysql_close();
?>
<input type="submit" name="action" value="OK">
</form>
<?
}//fin des changements ETAPE 1
// nous allons changer une commande : ETAPE 2
if(isset($_POST['action']) and $_POST['action']=='OK'){
if(empty($_POST['exqte']) ){
?>
<script ="Javascript">
history.go(-1);
</script>
<?
exit;
}
foreach ($_POST['exqte'] as $type =>$nbre){
if( $nbre==0 OR empty($nbre)){// si l'internaute à changé la quantité à 0
unset($_SESSION['panier'][$type]);
}
$_SESSION['panier'][$type]=$nbre;
}//fin du foreach
?>
<script ="Javascript">
location.replace('caddie.php');
</script>
<?
exit;
}//fin des changements ETAPE 2
?>
Page Caddie :<?
session_start();
include ("connection.php");
if( isset($_SESSION['panier']))
{
$panier = $_SESSION['panier'];
$tot=0;// initialisation du total.
?>
<div align="center"><H2>Votre Caddie</H2></div>
<table border="1" align="center" bgcolor="cccccc" width="50%">
<tr bgcolor='white'>
<td width="">Produit</td>
<td width="">Quantité</td>
<td width="">Px Unité</td>
<td width="">Total </td>
<td width=""> </td>
</tr>
<form method="POST" action="commande.php">
<?
require ("connection.php");
foreach ($panier as $valeur=>$cde)
{
$sql="select * from tblphotos where Id='$valeur'";
$req=mysql_query($sql)or exit ('Erreur SQL !'.$sql.'<br>'.mysql_error());
while( $data=mysql_fetch_array($req) )
{
$nom=$data['Index_Photo'];//référence de la photo
$prix=$data['Prixaveccadre'];// prix unitaire de la photo
$pxligne=$prix*$cde; //prix pour la ligne de commande
$tot+=$pxligne;//valorisation du total général
echo"<tr><td>$nom</td><td>$cde</td><td>$prix</td><td align='right'>$pxligne</td><td><input type='checkbox' name='case[]' value='".$data['Id']."'></td></tr>";
}
}
;
echo"<tr><td colspan='3' align='right'>Total Commandé...</td><td align='right'>$tot</td></tr>";
mysql_close();
}
?>
<tr bgcolor='white'>
<td colspan="5" align="right"><input type="submit" name="action" value="Eliminer"> <input type="submit" name="action" value="Changer"></td></tr></table>
</form>
<br><br><a href="boutique.php">Retour à la Boutique</a>