[eCommerce] Script de panier virtuel
voila j ai trouvait ce scripts de 3 pages sur internet et il ma ffiche dess erreurs que je ne vois pas car pour moi tout est bon voici le première page:
page de connexion:
// VOUS pouvez modifier ce fichier pour votre
//connexion à votre base.
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 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
| <?php
define ("USER", "root") ;
define ("PASSWORD", "") ;
$connexion = mysql_connect("localhost",USER,PASSWORD)
or exit("Erreur 101") ;
mysql_select_db( "menu" , $connexion)
or exit("Erreur 102") ;
?>
page panier4_1.php
<?session_start();
if(isset($_SESSION['panier']))
{
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']))
{
require('inc_connect.php');
$sql="Select* from fleuriste";
$req=mysql_query($sql,$connexion)or exit ('Erreur SQL !'.$sql.'<br>'.mysql_error());
while( $data=mysql_fetch_array($req) ) {
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();
?>
</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;
}
require('inc_connect.php');
$sql1="Select* from fleuriste where id=".$_GET['prod'];
$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">
<?
echo"<tr><td>".$data['nom']." </td><td colspan='2'> ".$data['prix']."</td></tr>".
"<tr><td colspan='3'align='center'>Quantité : <input type='text' name='qte' size='5'> <input type='submit' name='action' value='Cder'></td></tr>".
"<input name='id' type='hidden' value='".$data['id']."'>";
}
mysql_close();
?>
</table><br>
<div align="center"><a href="javascript:history.go(-1)"><< Retour Boutique</a></div> |
la page panier4_2.php:
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 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
| <?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 language="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
?> |
la page panier4_3.php:
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 41 42 43 44 45 46
|
<? 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> |
et enfin la base :
# Base de données: `menu`
#
# --------------------------------------------------------
#
# Structure de la table `fleuriste`
#
Code:
1 2 3 4 5 6 7
|
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 ; |
#
# Contenu de la table `fleuriste`
#
Code:
1 2 3 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'); |
tester ce code pour ma ider je vous en supplie c est hype important pour moi, j ai beau regarder les erreurs me rendent perplexe.merci encore.