Caddie et mysql

Fermé
marie13 - 16 avril 2010 à 22:25
 marie13 - 17 avril 2010 à 20:28
bonjour a vous
voila mon probleme j'ai creer une boutique ecmais mon panier et ma base de donnee je fonctionnent pas et je sais pas pourquoi voila mon code
pour la boutique

<?session_start();//demarrage de la session
if(isset($_SESSION['panier'])){//si il y a une comande dans le caddie alors on affiche un lien au caddie
echo"<div align='right'><a href='Panier4_3.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="">Noms</td>
<td width="">Px Unitaires</td>
<td width=""> </td>


</tr>
<?
if(!isset($_GET['prod'])){// pas de variable dans l'url
require('inc_connect.php');// connexion à la base
$sql="Select* from fleuriste";
$req=mysql_query($sql,$connexion)or exit ('Erreur SQL !'.$sql.'<br>'.mysql_error());
while( $data=mysql_fetch_array($req) ) {//la boucle pour l'affichage des données
echo"<tr><td>".$data['nom']." </td><td> ".$data['prix']."</td><td> <a href='panier4_1.php?prod=".$data['id']."'>Détail+Cde</a></td></tr>";
}
mysql_close();//n'oubliez pas de fermer la connexion !!
?>
</table>

<?}

if(isset($_GET['prod'])){//si la variable prod est passée par l'url
if(!is_numeric($_GET['prod'])){//juste une première sécurité
echo"<font color='red'>MERCI DE NE PLUS RECOMMENCER CETTE OPERATION !!!</font>";
exit;
}
require('inc_connect.php');
$sql1="Select* from fleuriste where id=".$_GET['prod'];//nous interrogeons la table sur l'id de la fleur
$req1=mysql_query($sql1,$connexion)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:
while( $data=mysql_fetch_array($req1) ) {
?>
<form method="POST" action="Panier4_2.php"> //Formulaire qui enverra les données sur la page de traitement
<?

echo"<tr><td>".$data['nom']." </td><td colspan='2'> ".$data['prix']."</td></tr>".
// le champ qui récupèrera le nbre de fleurs commandées.
"<tr><td colspan='3'align='center'>Quantité : <input type='text' name='qte' size='5'> <input type='submit' name='action' value='Cder'></td></tr>".//bouton de validation
"<input name='id' type='hidden' value='".$data['id']."'>";//trés important, en champ caché l'ID de la fleur
}
mysql_close();
?>

</table><br>
<div align="center"><a href="javascript:history.go(-1)"><< Retour Boutique</a></div>
<?
}

?>



pour le traitement

<?session_start();

// nous allons enregistrer une commande
if(isset($_POST['action']) and $_POST['action']=="Cder"){
echo$_POST['id']."<br>".$_POST['qte']."<br><BR>";
$id=$_POST['id'];
$qte=$_POST['qte'];
if( empty($_SESSION['panier'][$id]) ){
$_SESSION['panier'][$id]=$qte;
}else{

$_SESSION['panier'][$id]+=$qte;
}
?>
<script language="javascript">
window.location.replace("panier4_1.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 language="Javascript">
window.location.replace('Panier4_3.php');
</script>
<?
exit;
}//fin delete


// nous allons changer une comande : Etape 1 ==> l'affichage
if(isset($_POST['action']) and $_POST['action']=='Changer'){
if(empty($_POST['case']) ){
?>
<script language="Javascript">
history.go(-1);
</script>
<?
exit;
}
?>
<form method="POST" action="">
<?
require('inc_connect.php');
foreach($_POST['case'] as $modif){
$sql="Select* from fleuriste where id='$modif'";
$req=mysql_query($sql,$connexion)or exit ('Erreur SQL !'.$sql.'<br>'.mysql_error());
while( $data=mysql_fetch_array($req) ) {
echo"<b>Produit :</b> <i>".$data['nom']."</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 comande : 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 language="Javascript">
window.location.replace('Panier4_3.php');
</script>
<?
exit;
}//fin des changements ETAPE 2
?>
et pour le panier

<? session_start();
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="Panier4_2.php">

<?
$connexion = mysql_connect("localhost","root","")
or exit("Erreur 101") ;
mysql_select_db( "menu" , $connexion)
or exit("Erreur 102") ;
foreach ($panier as $valeur=>$cde){

$sql="select * from fleuriste where id='$valeur'";
$req=mysql_query($sql)or exit ('Erreur SQL !'.$sql.'<br>'.mysql_error());
while( $data=mysql_fetch_array($req) ){
$nom=$data['nom'];//nom de la fleur
$prix=$data['prix'];// prix unitaire de la fleur
$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'>".number_format($pxligne, 2,'.',' ')."</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'>".number_format($tot, 2,'.',' ')."</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="Panier4_1.php">Retour à la Boutique</a>

sachant que j'ai creer ma bdd
CREATE TABLE 'fleuriste' (
'id' tinyint(5) unsigned NOT NULL auto_increment,
'nom' varchar(20) NOT NULL default '',
'prix' decimal(5,2) unsigned NOT NULL default '0.00',
KEY 'id' ('id')
) TYPE=MyISAM AUTO_INCREMENT=4 ;

INSERT INTO 'fleuriste' VALUES (1, 'Roses', '1.75');
INSERT INTO 'fleuriste' VALUES (2, 'Tulipes', '2.25');
INSERT INTO 'fleuriste' VALUES (3, 'Oeillets', '3.50');

aidez moi svp si cela marche ca serai le top svpppppppppppppppppppppp le plus tot possible j'en ai vrrrraiment besoin
merci d'avance

1 réponse

bonjour
alors les amis une reponse svp
merci
0