Bonjour,SVP aider moi c vraiment urgent svp
un vehicule a troix prix
1) prix ttc
2 ) prix anseig
3) prix moudjahid
donc comment faire une fonction qui permet a un client inscris d'afficher son prix qui convient c'est a dire j'ai fais un panier d'achat donc lequel il me renvois le prix du véhicule tous depend du client
voici le programme panier_fonction.php
<?php
include('connexion.php');
function creationPanier(){
if (!isset($_SESSION['panier'])){
$_SESSION['panier']=array();
$_SESSION['panier']['ident'] = array();
$_SESSION['panier']['refProduit'] = array();
$_SESSION['panier']['qteProduit'] = array();
$_SESSION['panier']['prixProduit'] = array();
$_SESSION['panier']['verrou'] = false;
}
return true;
}
function ajouterArticle($ident,$refart,$qteProduit,$prixProduit){
//Si le panier existe
if (creationPanier() && !isVerrouille())
{
//Si le produit existe déjà on ajoute seulement la quantité
$positionProduit = array_search($refart, $_SESSION['panier']['refProduit']);
if ($positionProduit !== false)
{
$_SESSION['panier']['qteProduit'][$positionProduit] += $qteProduit ;
}
else
{
//Sinon on ajoute le produit
array_push( $_SESSION['panier']['ident'],$ident);
array_push( $_SESSION['panier']['refProduit'],$refart);
array_push( $_SESSION['panier']['qteProduit'],$qteProduit);
array_push( $_SESSION['panier']['prixProduit'],$prixProduit);
}
}
else
echo "Un problème est survenu veuillez contacter l'administrateur du site.";
}
function modifierQTeArticle($refart,$qteProduit){
//Si le panier éxiste
if (creationPanier() && !isVerrouille())
{
//Si la quantité est positive on modifie sinon on supprime l'article
if ($qteProduit > 0)
{
//Recharche du produit dans le panier
$positionProduit = array_search($refart, $_SESSION['panier']['refProduit']);
if ($positionProduit !== false)
{
$_SESSION['panier']['qteProduit'][$positionProduit] = $qteProduit ;
}
}
else
supprimerArticle($refart);
}
else
echo "Un problème est survenu veuillez contacter l'administrateur du site.";
}
function supprimerArticle($refart){
//Si le panier existe
if (creationPanier() && !isVerrouille())
{
//Nous allons passer par un panier temporaire
$tmp=array();
$tmp['ident'] = array();
$tmp['refProduit'] = array();
$tmp['qteProduit'] = array();
$tmp['prixProduit'] = array();
$tmp['verrou'] = $_SESSION['panier']['verrou'];
for($i = 0; $i < count($_SESSION['panier']['refProduit']); $i++)
{
if ($_SESSION['panier']['refProduit'][$i] !== $refart)
{
array_push( $tmp['ident'],$_SESSION['panier']['ident'][$i]);
array_push( $tmp['refProduit'],$_SESSION['panier']['refProduit'][$i]);
array_push( $tmp['qteProduit'],$_SESSION['panier']['qteProduit'][$i]);
array_push( $tmp['prixProduit'],$_SESSION['panier']['prixProduit'][$i]);
}
}
//On remplace le panier en session par notre panier temporaire à jour
$_SESSION['panier'] = $tmp;
//On efface notre panier temporaire
unset($tmp);
}
else
echo "Un problème est survenu veuillez contacter l'administrateur du site.";
}
function MontantGlobal(){
$total=0;
for($i = 0; $i < count($_SESSION['panier']['refProduit']); $i++)
{
$total += $_SESSION['panier']['qteProduit'][$i] * $_SESSION['panier']['prixProduit'][$i];
}
return $total;
}
function supprimePanier(){
unset($_SESSION['panier']);
}
function isVerrouille(){
if (isset($_SESSION['panier']) && $_SESSION['panier']['verrou'])
return true;
else
return false;
}
function compterArticles()
{
if (isset($_SESSION['panier']))
return count($_SESSION['panier']['refProduit']);
else
return 0;
}
function validercommande($ident)
{
$connection = mysql_connect("localhost","root","");
if ( ! $connection )
die ("connection impossible");
//On sélectionne la BDD
$mabasededonnee="bdd";
mysql_select_db($mabasededonnee) or die ("pas de connection");
if (creationPanier())
{
isVerrouille();
$montant=MontantGlobal();
$client=$_SESSION['log_cli'];
$req ="INSERT INTO commande (num_com,login_client,montant_com,valid_cmd,date_com) VALUES ('','$client','$montant','0',curdate())";
mysql_query($req,$connection);
$az=mysql_query("select max(num_com)from commande");
$k=0;
while ($k<mysql_num_rows($az))
{
$zz=mysql_fetch_row($az);
$num_comm=$zz[0];
$k=$k+1;
}
for($i = 0; $i < count($_SESSION['panier']['refProduit']); $i++)
{
$num_produit= $_SESSION['panier']['ident'][$i];
$qtt_produit= $_SESSION['panier']['qteProduit'][$i];
$requete ="INSERT INTO commande_vehicule (id_vehi,num_vehi,num_commande,qtt) VALUES ('','$num_produit','$num_comm','$qtt_produit')";
mysql_query($requete,$connection);
}
mysql_close($connection);
supprimePanier();
header("Location: commande_cli_veh.php") ;
}
}
?>
et voici le code de mon_panier_veh.php
<?php
session_start();
if(isset($_SESSION['log_cli'])){
?>
<?php
include_once("panier_fct_vehi.php");
$erreur = false;
$action = (isset($_POST['action'])? $_POST['action']: (isset($_GET['action'])? $_GET['action']:null )) ;
if($action !== null)
{
if(!in_array($action,array('ajout', 'suppression', 'refresh', 'valider')))
$erreur=true;
//récuperation des variables en POST ou GET
$id = (isset($_POST['id'])? $_POST['id']: (isset($_GET['id'])? $_GET['id']:null )) ;
$l = (isset($_POST['l'])? $_POST['l']: (isset($_GET['l'])? $_GET['l']:null )) ;
$p = (isset($_POST['p'])? $_POST['p']: (isset($_GET['p'])? $_GET['p']:null )) ;
$q = (isset($_POST['q'])? $_POST['q']: (isset($_GET['q'])? $_GET['q']:null )) ;
//Suppression des espaces verticaux
$l = preg_replace('#\v#', '',$l);
//On verifie que $p soit un float
$p = floatval($p);
//On traite $q qui peut etre un entier simple ou un tableau d'entier
if (is_array($q)){
$QteArticle = array();
$i=0;
foreach ($q as $contenu){
$QteArticle[$i++] = intval($contenu);
}
}
else
$q = intval($q);
}
if (!$erreur){
switch($action){
Case "ajout":
ajouterArticle($id,$l,$q,$p);
break;
Case "suppression":
supprimerArticle($l);
break;
Case "refresh" :
for ($i = 0 ; $i < count($QteArticle) ; $i++)
{
modifierQTeArticle($_SESSION['panier']['refProduit'][$i],round($QteArticle[$i]));
}
break;
Case "valider":
validercommande($id);
break;
Default:
break;
}
}
echo '<?xml version="1.0" encoding="utf-8"?>';?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Panier véhicule</title>
<style type="text/css">
<!--
body {
background-repeat: repeat-x;
background-image: url(image/fond_degrader.jpg);
}
.Style1 {
font-size: x-large;
font-style: italic;
font-weight: bold;
}
#a{
border-style: solid solid solid solid;
border-color: #eee;
width: 400px;
margin: auto;
margin-top:10px;
border-width: 8px;
background:#eee;
-moz-border-radius: 15px 15px 15px 15px / 15px 15px 15px 15px;
-webkit-border-radius: 15px 15px 15px 15px / 15px 15px 15px 15px;
-khtml-border-radius: 15px 15px 15px 15px / 15px 15px 15px 15px;
border-radius: 15px 15px 15px 15px / 15px 15px 15px 15px;
}
#centre {
min-height:150px;
width: 850px;
margin: auto;
margin-top:15px;
text-align: left;
border-style: solid solid none solid;
border-color: #564EA3;
border-width: 1px;
background: #ffffff;
-moz-border-radius: 15px 15px 15px 15px / 15px 15px 15px 15px;
-webkit-border-radius: 15px 15px 15px 15px / 15px 15px 15px 15px;
-khtml-border-radius: 15px 15px 15px 15px / 15px 15px 15px 15px;
border-radius: 15px 15px 15px 15px / 15px 15px 15px 15px;
}
#r {
background-image: url(image/9609580-multicolore-banniere-ondee-vif-avec-des-etoiles.jpg);
width: 850px;
-moz-border-radius: 15px 15px 15px 15px / 15px 15px 15px 15px;
-webkit-border-radius: 15px 15px 15px 15px / 15px 15px 15px 15px;
-khtml-border-radius: 15px 15px 15px 15px / 15px 15px 15px 15px;
border-radius: 15px 15px 15px 15px / 15px 15px 15px 15px;
}
#ok {
height:516px;
overflow:scroll;
border-style: solid solid none solid;
border-color: #677D92;
border-width: 2px;
margin-top:0px;
/* Haurizental/Vertical (H-Gauche H-Droite B-Droite B-Gauche)*/
-moz-border-radius: 15px 15px 0px 0px / 15px 15px 0px 0px;
-webkit-border-radius: 15px 15px 0px 0px / 15px 15px 0px 0px;
-khtml-border-radius: 15px 15px 0px 0px / 15px 15px 0px 0px;
border-radius: 15px 15px 0px 0px / 15px 15px 0px 0px;
}
#sam {
border-style: solid solid none solid;
border-color: #677D92;
border-width: 2px;
background:#ffffff;
/* Haurizental/Vertical (H-Gauche H-Droite B-Droite B-Gauche)*/
-moz-border-radius: 15px 15px 0px 0px / 15px 15px 0px 0px;
-webkit-border-radius: 15px 15px 0px 0px / 15px 15px 0px 0px;
-khtml-border-radius: 15px 15px 0px 0px / 15px 15px 0px 0px;
border-radius: 15px 15px 0px 0px / 15px 15px 0px 0px;
}
#g img{
/* Haurizental/Vertical (H-Gauche H-Droite B-Droite B-Gauche)*/
-moz-border-radius: 15px 15px 15px 15px / 15px 15px 15px 15px;
-webkit-border-radius: 15px 15px 15px 15px / 15px 15px 15px 15px;
-khtml-border-radius: 15px 15px 15px 15px / 15px 15px 15px 15px;
border-radius: 15px 15px 15px 15px / 15px 15px 15px 15px;
}
.Style2 {
font-size: 36px;
font-style: italic;
font-weight: bold;
}
#a { border-style: solid solid solid solid;
border-color: #eee;
width: 400px;
margin: auto;
margin-top:10px;
border-width: 8px;
background:#eee;
-moz-border-radius: 15px 15px 15px 15px / 15px 15px 15px 15px;
-webkit-border-radius: 15px 15px 15px 15px / 15px 15px 15px 15px;
-khtml-border-radius: 15px 15px 15px 15px / 15px 15px 15px 15px;
border-radius: 15px 15px 15px 15px / 15px 15px 15px 15px;
}
.Style3 {font-family: "Times New Roman", Times, serif}
.Style4 {
color: #330066;
font-size: x-large;
}
.Style5 {font-size: xx-large}
-->
</style></head>
<body><div id="centre"><div id="r">
<table width="848" border="0">
<tr>
<td width="840" height="113"><div align="center" class="Style2">DBS AUTO </div></td>
</tr>
</table></div>
<table width="854" border="0">
<tr>
<td width="209" height="464"><div id="sam">
<table width="205" height="520" border="0">
<tr>
<td width="199" height="42"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="
http://fpdownload2.macromedia.com/get/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 " width="199" height="35">
<param name="BGCOLOR" value="" />
<param name="movie" value="button106.swf" />
<param name="quality" value="high" />
<embed src="button106.swf" quality="high" pluginspage="
https://get.adobe.com/flashplayer/ " type="application/x-shockwave-flash" width="199" height="35" ></embed>
</object></td>
</tr>
<tr>
<td height="53"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="
http://fpdownload2.macromedia.com/get/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 " width="199" height="35">
<param name="movie" value="button118.swf" />
<param name="quality" value="high" />
<embed src="button118.swf" quality="high" pluginspage="
https://get.adobe.com/flashplayer/ " type="application/x-shockwave-flash" width="199" height="35" ></embed>
</object></td>
</tr>
<tr>
<td height="50"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="
http://fpdownload2.macromedia.com/get/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 " width="199" height="35">
<param name="BGCOLOR" value="" />
<param name="movie" value="button19.swf" />
<param name="quality" value="high" />
<embed src="button19.swf" quality="high" pluginspage="
https://get.adobe.com/flashplayer/ " type="application/x-shockwave-flash" width="199" height="35" ></embed>
</object></td>
</tr>
<tr>
<td height="44"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="
http://fpdownload2.macromedia.com/get/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 " width="199" height="35">
<param name="BGCOLOR" value="" />
<param name="movie" value="button83.swf" />
<param name="quality" value="high" />
<embed src="button83.swf" quality="high" pluginspage="
https://get.adobe.com/flashplayer/ " type="application/x-shockwave-flash" width="199" height="35" ></embed>
</object></td>
</tr>
<tr>
<td height="51"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="
http://fpdownload2.macromedia.com/get/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 " width="199" height="35">
<param name="movie" value="button105.swf" />
<param name="quality" value="high" />
<embed src="button105.swf" quality="high" pluginspage="
https://get.adobe.com/flashplayer/ " type="application/x-shockwave-flash" width="199" height="35" ></embed>
</object></td>
</tr>
<tr>
<td height="45"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="
http://fpdownload2.macromedia.com/get/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 " width="199" height="35">
<param name="BGCOLOR" value="" />
<param name="movie" value="button96.swf" />
<param name="quality" value="high" />
<embed src="button96.swf" quality="high" pluginspage="
https://get.adobe.com/flashplayer/ " type="application/x-shockwave-flash" width="199" height="35" ></embed>
</object></td>
</tr>
<tr>
<td height="43"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="
http://fpdownload2.macromedia.com/get/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 " width="199" height="35">
<param name="movie" value="button107.swf" />
<param name="quality" value="high" />
<embed src="button107.swf" quality="high" pluginspage="
https://get.adobe.com/flashplayer/ " type="application/x-shockwave-flash" width="199" height="35" ></embed>
</object></td>
</tr>
<tr>
<td height="51"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="
http://fpdownload2.macromedia.com/get/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 " width="199" height="35">
<param name="movie" value="button85.swf" />
<param name="quality" value="high" />
<embed src="button85.swf" quality="high" pluginspage="
https://get.adobe.com/flashplayer/ " type="application/x-shockwave-flash" width="199" height="35" ></embed>
</object></td>
</tr>
<tr>
<td height="41"> </td>
</tr>
</table>
</div></td>
<td width="635"><div id="ok"><table width="584" height="510" border="0">
<tr>
<td width="573" height="77"><div align="center" class="Style1">
Votre panier
<p> </p>
</div></td>
</tr>
<tr>
<td height="430"><form id="form1" name="form1" method="post" action="mon_panier_vehi.php">
<table width="573" border="0">
<tr>
<td width="100" height="21">Libellé</td>
<td width="83">Quantité</td>
<td width="104">Prix unitaire </td>
<td width="249">Action</td>
</tr>
<?php
if (creationPanier())
{
$nbArticles=count($_SESSION['panier']['refProduit']);
if ($nbArticles <= 0)
echo "<tr><td></br></br>Votre panier est vide </ td></tr>";
else
{
for ($i=0 ;$i < $nbArticles ; $i++)
{
echo "<tr>";
echo "<td>".htmlspecialchars($_SESSION['panier']['refProduit'][$i])."</ td>";
echo "<td><input type=\"text\" size=\"4\" name=\"q[]\" value=\"".htmlspecialchars($_SESSION['panier']['qteProduit'][$i])."\"/></td>";
echo "<td>".htmlspecialchars($_SESSION['panier']['prixProduit'][$i])."</td>";
echo "<td><a href=\"".htmlspecialchars("mon_panier_vehi.php?action=suppression&l=".rawurlencode($_SESSION['panier']['refProduit'][$i]))."\">Supprimer</a></td>";
echo "</tr>";
}
echo "<tr><td colspan=\"2\"> </td>";
echo "<td colspan=\"2\">";
echo "</br></br>Total : ".MontantGlobal();
echo "</td></tr>";
echo "<tr><td colspan=\"4\">";
echo "<input type=\"submit\" value=\"Rafraichir\"/>";
echo "<input type=\"hidden\" name=\"action\" value=\"refresh\"/>";
echo "</td></tr>";
echo "<td colspan=\"2\" >";
echo "</br><div id='raf'><a href=\"".htmlspecialchars("mon_panier_vehi.php?action=valider&id=".$_SESSION['panier']['ident'])."\">Commander</a></div>";
echo "</td></tr>";
}
}
?>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td width="10"> </td>
<td width="10"> </td>
</tr>
</table>
</form>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p></td>
</tr>
</table>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</div></td>
</tr>
</table></div>
</body>
</html>
<?php
}else{header("Location: authentification_client.php");}
?>
Afficher la suite