par
Cyrano » 28 mai 2006, 09:50
Salut,
tu génères un code invalide, la balise <form> ne peut pas se trouver entre </tr> et <tr>. Ensuite, tu initialisses une variable $sessionidclient que tu n'utilises jamais, ce n'est pas d'une très grande utilité : proposition pour une première correction avant un autre problème :
<?php
session_start();
$sessionidclient = $_SESSION['id_client'];
echo $sessionidclient ." Identifiant client";
echo "<br><br>";
$article = $_POST['article'];
echo $article;
echo "<br>";
$quantite = $_POST['quantite'];
//connexion à la BDD
$req1 = "SELECT ref_produit, prix_produit ".
"FROM produit ".
"WHERE designation_produit = '".$article."'";
$query1 = mysql_query($req1) or die(mysql_error());
$fetch1 = mysql_fetch_array($query1);
$total = $fetch1['prix_produit']*$quantite;
$inser = "INSERT INTO panier (id_cli, ref_produit, quantite, total) ".
"VALUES ( '".$_SESSION['id_client']."','".$fetch1['ref_produit']."', '".$quantite."', '".$total."')";
$inquer = mysql_query($inser) or die(mysql_error());
$affected = mysql_affected_rows();
$reqtot = "SELECT sum(total) ".
"FROM panier ".
"WHERE id_cli = '".$_SESSION['id_client']."' ";
$querytot = mysql_query($reqtot) or die(mysql_error());
$fetchtot = mysql_fetch_array($querytot);
if(isset($_POST['sub_form']) && $_POST['sub_form'] == 'modifier')
{
$modif = "UPDATE panier ".
"SET quantite = '". $_POST['quantite'] ."', total = '". $fetch1['prix_produit'] * $_POST['quantite'] ."' ".
"WHERE ref_produit = '".$fetch1['ref_produit']."' ".
"AND id_cli = '". $sessionidclient ."'";
$res = mysql_query($modif) or die (mysql_error());
}
$select = "SELECT ref_produit, quantite, total ".
"FROM panier ".
"WHERE id_cli = '". $sessionidclient ."' ";
$quersel = mysql_query($select) or die(mysql_error());
?>
<table border="2">
<tr>
<td>
<center><b>Reference</b></center>
</td>
<td>
<center><b>Quantite</b></center>
</td>
<td>
<center><b>Total produit</b></center>
</td>
<td>Modifier</td>
</tr>
<?php
while($fetchsel = mysql_fetch_assoc($quersel))
{
?>
<tr>
<td colspan="4">
<form method="post" action="<?php echo($_SERVER['PHP_SELF']); ?>">
<table>
<tr>
<td><?php echo($fetchsel['ref_produit']); ?></td>
<td><input type="text" name="quantite" value="<?php echo($fetchsel['quantite']); ?>" ></td>
<td><?php echo($fetchsel['total']); ?></td>
<td><input type="submit" name="sub_form" value="modifier"></td>
</tr>
</table>
</form>
</td>
</tr>
<?php
}
?>
</table>
Au moins, ton code html aura plus de sens.
Maintenant, il reste un problème: tu génères un formulaire par tour de boucle : tu te retrouves avec autant de fois les mêmes éléments de formulaire ayant tous les mêmes noms : comment distingueras-tu un formulaire de l'autre ?
Suggestion : crée un seul formulaire global, mais crée des noms pour les champs dynamiquement dans ta boucle en concaténant les noms avec une variable incrémentée à chaque tour.
Salut,
tu génères un code invalide, la balise <form> ne peut pas se trouver entre </tr> et <tr>. Ensuite, tu initialisses une variable $sessionidclient que tu n'utilises jamais, ce n'est pas d'une très grande utilité : proposition pour une première correction avant un autre problème :
[php]<?php
session_start();
$sessionidclient = $_SESSION['id_client'];
echo $sessionidclient ." Identifiant client";
echo "<br><br>";
$article = $_POST['article'];
echo $article;
echo "<br>";
$quantite = $_POST['quantite'];
//connexion à la BDD
$req1 = "SELECT ref_produit, prix_produit ".
"FROM produit ".
"WHERE designation_produit = '".$article."'";
$query1 = mysql_query($req1) or die(mysql_error());
$fetch1 = mysql_fetch_array($query1);
$total = $fetch1['prix_produit']*$quantite;
$inser = "INSERT INTO panier (id_cli, ref_produit, quantite, total) ".
"VALUES ( '".$_SESSION['id_client']."','".$fetch1['ref_produit']."', '".$quantite."', '".$total."')";
$inquer = mysql_query($inser) or die(mysql_error());
$affected = mysql_affected_rows();
$reqtot = "SELECT sum(total) ".
"FROM panier ".
"WHERE id_cli = '".$_SESSION['id_client']."' ";
$querytot = mysql_query($reqtot) or die(mysql_error());
$fetchtot = mysql_fetch_array($querytot);
if(isset($_POST['sub_form']) && $_POST['sub_form'] == 'modifier')
{
$modif = "UPDATE panier ".
"SET quantite = '". $_POST['quantite'] ."', total = '". $fetch1['prix_produit'] * $_POST['quantite'] ."' ".
"WHERE ref_produit = '".$fetch1['ref_produit']."' ".
"AND id_cli = '". $sessionidclient ."'";
$res = mysql_query($modif) or die (mysql_error());
}
$select = "SELECT ref_produit, quantite, total ".
"FROM panier ".
"WHERE id_cli = '". $sessionidclient ."' ";
$quersel = mysql_query($select) or die(mysql_error());
?>
<table border="2">
<tr>
<td>
<center><b>Reference</b></center>
</td>
<td>
<center><b>Quantite</b></center>
</td>
<td>
<center><b>Total produit</b></center>
</td>
<td>Modifier</td>
</tr>
<?php
while($fetchsel = mysql_fetch_assoc($quersel))
{
?>
<tr>
<td colspan="4">
<form method="post" action="<?php echo($_SERVER['PHP_SELF']); ?>">
<table>
<tr>
<td><?php echo($fetchsel['ref_produit']); ?></td>
<td><input type="text" name="quantite" value="<?php echo($fetchsel['quantite']); ?>" ></td>
<td><?php echo($fetchsel['total']); ?></td>
<td><input type="submit" name="sub_form" value="modifier"></td>
</tr>
</table>
</form>
</td>
</tr>
<?php
}
?>
</table>[/php]
Au moins, ton code html aura plus de sens.
Maintenant, il reste un problème: tu génères un formulaire par tour de boucle : tu te retrouves avec autant de fois les mêmes éléments de formulaire ayant tous les mêmes noms : comment distingueras-tu un formulaire de l'autre ?
Suggestion : crée un seul formulaire global, mais crée des noms pour les champs dynamiquement dans ta boucle en concaténant les noms avec une variable incrémentée à chaque tour.