par
Chile » 10 juin 2006, 17:55
Salut,
Merci Cyrano pour l'illustration. Je comprends mieux le concept du panier, et ce a quoi je dois parvenir. Par contre pour mettre ca en pratique sur ca va pas etre de la rigolade
Il va falloir que je retouche la struture de mon site car jusqu'a maintenant, je remplissait le panier avec la variable "$_SESSION['MM_Username']" du visiteur connecté. et reconnu sur chaque page avec <?php session_start(); ?>.
En plus vu que je ne suis pas doué, je me sers de Dreamweaver qui me code une grande partie de mes pages que je complete si besoin
Jusqu'a maintenant j'ai par exemple sur ma page panier:
-une requete sur une table "client" avec $_SESSION['MM_Username'] (au cas ou le visiteur est dekja client et qu'il se connecte)
-une requete sur table "produits", avec $_GET['id'], pour recuperer les infos du produit a mettre dans le panier.
-une requete avancé "panier", avec $_SESSION['MM_Username'] pour afficher le contenu du panier en cours de ce client.(avec channgement quantité)
-une requete "total", avec $_SESSION['MM_Username'], pour le total
- et une requete simple "panier_aff" , avec $_SESSION['MM_Username'] pour afficher en parmanence et sur chaque page le contenu du panier en cours.
Dois je remplacer ma session_start() par session_id() ?
J'ai bien compris que je dois seulement recolter les infos perso du visiteur a la commande et donc a la fin. Mais si celui-ci se connecte avant ! ou seront-elle conserver en attendant la commande et avec quelle variable ?
quelle variable vais-je utiliser pour remplir le panier ?
beaucoup de questions...car je suis perdu
voici mon code a tout hasard...
<?php require_once('connect.php'); ?>
<?php session_start(); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "panier")) {
$updateSQL = sprintf("UPDATE shop_panier SET client=%s, quantite=%s WHERE id=%s AND article=%s",
GetSQLValueString($_POST['client'], "text"),
GetSQLValueString($_POST['quantite'], "int"),
GetSQLValueString($_POST['id'], "int"),
GetSQLValueString($_POST['article'], "int"));
mysql_select_db($database_boutique, $boutique);
$Result1 = mysql_query($updateSQL, $boutique) or die(mysql_error());
$updateGoTo = "panier.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "validation")) {
$insertSQL = sprintf("INSERT INTO shop_commande (client, `date`, total_ht, total_ttc) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['client'], "text"),
GetSQLValueString($_POST['date'], "date"),
GetSQLValueString($_POST['total_ht'], "int"),
GetSQLValueString($_POST['total_ttc'], "int"));
mysql_select_db($database_boutique, $boutique);
$Result1 = mysql_query($insertSQL, $boutique) or die(mysql_error());
$insertGoTo = "traitement_panier.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
session_start(); ?>
<?php
$colname_enr_clients = "1";
if (isset($_SESSION['MM_Username'])) {
$colname_enr_clients = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_boutique, $boutique);
$query_enr_clients = sprintf("SELECT * FROM shop_clients WHERE mail = '%s'", $colname_enr_clients);
$enr_clients = mysql_query($query_enr_clients, $boutique) or die(mysql_error());
$row_enr_clients = mysql_fetch_assoc($enr_clients);
$totalRows_enr_clients = mysql_num_rows($enr_clients);
$colname_livre = "1";
if (isset($_GET['id'])) {
$colname_livre = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_boutique, $boutique);
$query_livre = sprintf("SELECT * FROM shop_produits WHERE id = %s", $colname_livre);
$livre = mysql_query($query_livre, $boutique) or die(mysql_error());
$row_livre = mysql_fetch_assoc($livre);
$totalRows_livre = mysql_num_rows($livre);
$paramclient_panier = "0";
if (isset($_SESSION['MM_Username'])) {
$paramclient_panier = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_boutique, $boutique);
$query_panier = sprintf("SELECT shop_panier.*, shop_produits.titre, shop_produits.photo1p, shop_produits.prix_ht, shop_produits.prix_ttc, (shop_produits.prix_ttc*shop_panier.quantite) AS total_ttc, (shop_produits.prix_ht*shop_panier.quantite) AS total_ht FROM shop_panier INNER JOIN shop_produits ON shop_panier.article=shop_produits.id WHERE client = '%s'", $paramclient_panier);
$panier = mysql_query($query_panier, $boutique) or die(mysql_error());
$row_panier = mysql_fetch_assoc($panier);
$totalRows_panier = mysql_num_rows($panier);
$paramclient_total = "0";
if (isset($_SESSION['MM_Username'])) {
$paramclient_total = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_boutique, $boutique);
$query_total = sprintf("SELECT now() AS date, SUM(shop_panier.quantite*shop_produits.prix_ttc) AS total_ttc, SUM(shop_panier.quantite*shop_produits.prix_ht) AS total_ht FROM shop_panier INNER JOIN shop_produits ON shop_produits.id=shop_panier.article WHERE client = '%s' GROUP BY shop_panier.client", $paramclient_total);
$total = mysql_query($query_total, $boutique) or die(mysql_error());
$row_total = mysql_fetch_assoc($total);
$totalRows_total = mysql_num_rows($total);
$colname_aff_panier = "1";
if (isset($_SESSION['MM_Username'])) {
$colname_aff_panier = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_boutique, $boutique);
$query_aff_panier = sprintf("SELECT * FROM shop_panier WHERE client = '%s'", $colname_aff_panier);
$aff_panier = mysql_query($query_aff_panier, $boutique) or die(mysql_error());
$row_aff_panier = mysql_fetch_assoc($aff_panier);
$totalRows_aff_panier = mysql_num_rows($aff_panier);
?>
Salut,
Merci Cyrano pour l'illustration. Je comprends mieux le concept du panier, et ce a quoi je dois parvenir. Par contre pour mettre ca en pratique sur ca va pas etre de la rigolade :)
Il va falloir que je retouche la struture de mon site car jusqu'a maintenant, je remplissait le panier avec la variable "$_SESSION['MM_Username']" du visiteur connecté. et reconnu sur chaque page avec <?php session_start(); ?>.
En plus vu que je ne suis pas doué, je me sers de Dreamweaver qui me code une grande partie de mes pages que je complete si besoin :?
Jusqu'a maintenant j'ai par exemple sur ma page panier:
-une requete sur une table "client" avec $_SESSION['MM_Username'] (au cas ou le visiteur est dekja client et qu'il se connecte)
-une requete sur table "produits", avec $_GET['id'], pour recuperer les infos du produit a mettre dans le panier.
-une requete avancé "panier", avec $_SESSION['MM_Username'] pour afficher le contenu du panier en cours de ce client.(avec channgement quantité)
-une requete "total", avec $_SESSION['MM_Username'], pour le total
- et une requete simple "panier_aff" , avec $_SESSION['MM_Username'] pour afficher en parmanence et sur chaque page le contenu du panier en cours.
Dois je remplacer ma session_start() par session_id() ? :?
J'ai bien compris que je dois seulement recolter les infos perso du visiteur a la commande et donc a la fin. Mais si celui-ci se connecte avant ! ou seront-elle conserver en attendant la commande et avec quelle variable ?
quelle variable vais-je utiliser pour remplir le panier ?
beaucoup de questions...car je suis perdu :cry:
voici mon code a tout hasard...
[php]<?php require_once('connect.php'); ?>
<?php session_start(); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "panier")) {
$updateSQL = sprintf("UPDATE shop_panier SET client=%s, quantite=%s WHERE id=%s AND article=%s",
GetSQLValueString($_POST['client'], "text"),
GetSQLValueString($_POST['quantite'], "int"),
GetSQLValueString($_POST['id'], "int"),
GetSQLValueString($_POST['article'], "int"));
mysql_select_db($database_boutique, $boutique);
$Result1 = mysql_query($updateSQL, $boutique) or die(mysql_error());
$updateGoTo = "panier.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "validation")) {
$insertSQL = sprintf("INSERT INTO shop_commande (client, `date`, total_ht, total_ttc) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['client'], "text"),
GetSQLValueString($_POST['date'], "date"),
GetSQLValueString($_POST['total_ht'], "int"),
GetSQLValueString($_POST['total_ttc'], "int"));
mysql_select_db($database_boutique, $boutique);
$Result1 = mysql_query($insertSQL, $boutique) or die(mysql_error());
$insertGoTo = "traitement_panier.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
session_start(); ?>
<?php
$colname_enr_clients = "1";
if (isset($_SESSION['MM_Username'])) {
$colname_enr_clients = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_boutique, $boutique);
$query_enr_clients = sprintf("SELECT * FROM shop_clients WHERE mail = '%s'", $colname_enr_clients);
$enr_clients = mysql_query($query_enr_clients, $boutique) or die(mysql_error());
$row_enr_clients = mysql_fetch_assoc($enr_clients);
$totalRows_enr_clients = mysql_num_rows($enr_clients);
$colname_livre = "1";
if (isset($_GET['id'])) {
$colname_livre = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_boutique, $boutique);
$query_livre = sprintf("SELECT * FROM shop_produits WHERE id = %s", $colname_livre);
$livre = mysql_query($query_livre, $boutique) or die(mysql_error());
$row_livre = mysql_fetch_assoc($livre);
$totalRows_livre = mysql_num_rows($livre);
$paramclient_panier = "0";
if (isset($_SESSION['MM_Username'])) {
$paramclient_panier = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_boutique, $boutique);
$query_panier = sprintf("SELECT shop_panier.*, shop_produits.titre, shop_produits.photo1p, shop_produits.prix_ht, shop_produits.prix_ttc, (shop_produits.prix_ttc*shop_panier.quantite) AS total_ttc, (shop_produits.prix_ht*shop_panier.quantite) AS total_ht FROM shop_panier INNER JOIN shop_produits ON shop_panier.article=shop_produits.id WHERE client = '%s'", $paramclient_panier);
$panier = mysql_query($query_panier, $boutique) or die(mysql_error());
$row_panier = mysql_fetch_assoc($panier);
$totalRows_panier = mysql_num_rows($panier);
$paramclient_total = "0";
if (isset($_SESSION['MM_Username'])) {
$paramclient_total = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_boutique, $boutique);
$query_total = sprintf("SELECT now() AS date, SUM(shop_panier.quantite*shop_produits.prix_ttc) AS total_ttc, SUM(shop_panier.quantite*shop_produits.prix_ht) AS total_ht FROM shop_panier INNER JOIN shop_produits ON shop_produits.id=shop_panier.article WHERE client = '%s' GROUP BY shop_panier.client", $paramclient_total);
$total = mysql_query($query_total, $boutique) or die(mysql_error());
$row_total = mysql_fetch_assoc($total);
$totalRows_total = mysql_num_rows($total);
$colname_aff_panier = "1";
if (isset($_SESSION['MM_Username'])) {
$colname_aff_panier = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_boutique, $boutique);
$query_aff_panier = sprintf("SELECT * FROM shop_panier WHERE client = '%s'", $colname_aff_panier);
$aff_panier = mysql_query($query_aff_panier, $boutique) or die(mysql_error());
$row_aff_panier = mysql_fetch_assoc($aff_panier);
$totalRows_aff_panier = mysql_num_rows($aff_panier);
?>[/php]