fgiuliano
Habitué
Bonjour à tous,
Je suis en train de tourner en rond et je ne vois pas que faire pour m'en sortir...
J'ai un formulaire qui me permet de sélectionner des choix avec des checkbox et j'aimerai que si tel ou tel choix est sélectionné, la somme totale s'incrémente.
Pour cela, je fais un if qui vérifie si le $choix est égal à une valeur de mon tableau et si oui, j'incrémente ma somme...
Mais malheureusement , on entre jamais dans mon if...
Voilà mon code:
[cpp]
<?php
include("secure.php");
include("pcdb.php");
$connexion = mysql_connect($hote, $utilisateur, $mdp);
$choix_base = mysql_select_db($data_base, $connexion)or die("Impossible d'ouvrir le fichier de comptes");
if(isset($_POST['Total']))
{
if(!empty($_POST['commande']))
{
$commande = $_POST['commande'];
$sql = "SELECT libelle, prix FROM prix, produit WHERE produit.idproduit = prix.idproduit";
$req = mysql_query($sql) or die (mysql_error());
while ($data = mysql_fetch_array($req))
{
$libelle = $data['libelle'];
foreach($commande as $choix)
{
echo '$data: '.$libelle;?><br /><?php
echo '$choix: '.$choix;?><br /><?php
echo $data['prix'];?><br /><br /><?php
if($libelle == $choix)
{
echo 'Somme Avant: '.$somme;
$prix = $data['prix'];
$somme = $somme + $prix;
echo $data['prix'];
echo 'Somme Après: '.$somme;
}
}
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
<title>LOGEM SOFTWARE ENGINEERING SA - Achat licence</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="description" content="LOGEM SOFTWARE ENGINEERING SA" />
<meta name="keywords" content="aide à la planification" />
</head>
<body>
<form action="test2.php" method="post">
<?php
$sql = "SELECT produit.idproduit, libelle, prix FROM prix, produit WHERE produit.idproduit = prix.idproduit";
$req = mysql_query($sql) or die(mysql_error());
while ($data = mysql_fetch_array($req))
{
?>
<div>
<span><input type="checkbox" name="commande[]" value=" <?php echo $data['libelle'];?>"><?php echo $data['libelle'];?></span>
<span>Prix:</span>
<span><?php echo $data['prix'];?></span>
</div>
<?php
}
mysql_close();
?>
<div><strong>Total: </strong><?php echo $somme; ?></div>
<div>
<span><input type="reset" name="Effacer" value="Effacer" /></span>
<span><input type="submit" name="Total" value="Total" /></span>
<span><input type="submit" name="Commander" value="Commander" /></span>
</div>
</form>
</body>
</html>
[/cpp]
Merci d'avance pour votre aide!
Je suis en train de tourner en rond et je ne vois pas que faire pour m'en sortir...
J'ai un formulaire qui me permet de sélectionner des choix avec des checkbox et j'aimerai que si tel ou tel choix est sélectionné, la somme totale s'incrémente.
Pour cela, je fais un if qui vérifie si le $choix est égal à une valeur de mon tableau et si oui, j'incrémente ma somme...
Mais malheureusement , on entre jamais dans mon if...
Voilà mon code:
[cpp]
<?php
include("secure.php");
include("pcdb.php");
$connexion = mysql_connect($hote, $utilisateur, $mdp);
$choix_base = mysql_select_db($data_base, $connexion)or die("Impossible d'ouvrir le fichier de comptes");
if(isset($_POST['Total']))
{
if(!empty($_POST['commande']))
{
$commande = $_POST['commande'];
$sql = "SELECT libelle, prix FROM prix, produit WHERE produit.idproduit = prix.idproduit";
$req = mysql_query($sql) or die (mysql_error());
while ($data = mysql_fetch_array($req))
{
$libelle = $data['libelle'];
foreach($commande as $choix)
{
echo '$data: '.$libelle;?><br /><?php
echo '$choix: '.$choix;?><br /><?php
echo $data['prix'];?><br /><br /><?php
if($libelle == $choix)
{
echo 'Somme Avant: '.$somme;
$prix = $data['prix'];
$somme = $somme + $prix;
echo $data['prix'];
echo 'Somme Après: '.$somme;
}
}
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
<title>LOGEM SOFTWARE ENGINEERING SA - Achat licence</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="description" content="LOGEM SOFTWARE ENGINEERING SA" />
<meta name="keywords" content="aide à la planification" />
</head>
<body>
<form action="test2.php" method="post">
<?php
$sql = "SELECT produit.idproduit, libelle, prix FROM prix, produit WHERE produit.idproduit = prix.idproduit";
$req = mysql_query($sql) or die(mysql_error());
while ($data = mysql_fetch_array($req))
{
?>
<div>
<span><input type="checkbox" name="commande[]" value=" <?php echo $data['libelle'];?>"><?php echo $data['libelle'];?></span>
<span>Prix:</span>
<span><?php echo $data['prix'];?></span>
</div>
<?php
}
mysql_close();
?>
<div><strong>Total: </strong><?php echo $somme; ?></div>
<div>
<span><input type="reset" name="Effacer" value="Effacer" /></span>
<span><input type="submit" name="Total" value="Total" /></span>
<span><input type="submit" name="Commander" value="Commander" /></span>
</div>
</form>
</body>
</html>
[/cpp]
Merci d'avance pour votre aide!