par
dread » 04 févr. 2008, 16:37
J'ai bien une boucle pour la requête qui insere les articles de la commande mais même quand je la met en commentaire et que je n'éxecute que la première, elle se répète deux fois.
Je vous mets le code de ma page entière:
<?php require_once('Connections/conn_panier.php');
mysql_select_db($database_conn_panier, $conn_panier);
mysql_query("SET NAMES 'utf8'");
/* Démarrage ou prolongation de la session */
session_start();
if ($_SESSION['panier']['verrouille']==true) {
echo 'oui';
} else {
echo 'non';
}
$datebdd=date("Y-m-d h:i:s");
$dateheure=date("Y-m-d-h-i-s");
$date=explode("-",$dateheure);
// on enregistre la commande dans la bdd
$query_rs_ajout = "SELECT MAX(id_commande)+1 as id_max FROM tbl_commande";
$rs_ajout = mysql_query($query_rs_ajout, $conn_panier) or die(mysql_error());
$row_rs_ajout = mysql_fetch_assoc($rs_ajout);
if($row_rs_ajout['id_max'] == '') {
$id = 1;
} else {
$id = $row_rs_ajout['id_max'];
}
$query_ajouter_commande = "INSERT INTO tbl_commande(id_commande, ref_commande, date_commande, mode_paiement, statut_reglement, transport_commande, statut_livraison, ref_livraison, client_id) VALUES
('".$id."',
'C".$date[0].$date[1].$date[2].$date[3].$date[4].$date[5]."',
'".$datebdd."',
'2',
'2',
'".mysql_real_escape_string($_SESSION['panier']['livraison'])."',
'2',
'',
'".mysql_real_escape_string($_SESSION['panier']['client'])."');";
$ajouter_commande = mysql_query($query_ajouter_commande);
echo $query_ajouter_commande;
//On enregistre les articles relatifs à la commande
$nb= count($_SESSION['panier']['id_article']);
$nombre=$nb-1;
for($i=1;$i<=$nombre; $i++) {
$query_rs_ajout2 = "SELECT MAX(id_produit)+1 as id_max2 FROM tbl_commande_produit";
$rs_ajout2 = mysql_query($query_rs_ajout2, $conn_panier) or die(mysql_error());
$row_rs_ajout2 = mysql_fetch_assoc($rs_ajout2);
if($row_rs_ajout2['id_max2'] == '') {
$id2 = 1;
} else {
$id2 = $row_rs_ajout2['id_max2'];
}
$query_rs_tva="SELECT tva_article, prix_article FROM tbl_article WHERE id_article='".$_SESSION['panier']['id_article'][$i]."'";
$rs_tva = mysql_query($query_rs_tva, $conn_panier) or die(mysql_error());
$row_rs_tva = mysql_fetch_assoc($rs_tva);
echo '<br/>'.$query_rs_tva;
$query_ajouter_produit = "INSERT INTO tbl_commande_produit(id_produit, ref_produit, qte_produit, prix_produit, tva_produit, commande_id) VALUES
('".$id2."',
'".mysql_real_escape_string($_SESSION['panier']['id_article'][$i])."',
'".mysql_real_escape_string($_SESSION['panier']['qte'][$i])."',
'".mysql_real_escape_string($row_rs_tva['prix_article'])."',
'".mysql_real_escape_string($row_rs_tva['tva_article'])."',
'".$id."');";
$ajouter_produit = mysql_query($query_ajouter_produit);
}
echo '<br/>'.$query_ajouter_produit;
echo '<br/>'.$_SESSION['panier']['reglement'];
?>
<!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" xml:lang="fr" lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Paiement par chèque</title>
<meta name=""/>
<meta name="Keywords" content=""/>
<link href="" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="global">
<p>Vous avez choisi un mode de règlement par chèque.</p>
<p>Vous voudrez bien nous l'envoyer à l'adresse suivante <b>adresse</b> avec pour libellé : et pour montant: <b><?php echo $_SESSION['panier']['reglement'].' €';?></b></p>
</div>
</body>
</html>
Si je met un exit(); à la fin de mes deux requêtes, juste avant le doctype, tout se passe bien.
Un peu étrange je trouve mais certainement pas inexplicable.
J'ai bien une boucle pour la requête qui insere les articles de la commande mais même quand je la met en commentaire et que je n'éxecute que la première, elle se répète deux fois.
Je vous mets le code de ma page entière:
[php]
<?php require_once('Connections/conn_panier.php');
mysql_select_db($database_conn_panier, $conn_panier);
mysql_query("SET NAMES 'utf8'");
/* Démarrage ou prolongation de la session */
session_start();
if ($_SESSION['panier']['verrouille']==true) {
echo 'oui';
} else {
echo 'non';
}
$datebdd=date("Y-m-d h:i:s");
$dateheure=date("Y-m-d-h-i-s");
$date=explode("-",$dateheure);
// on enregistre la commande dans la bdd
$query_rs_ajout = "SELECT MAX(id_commande)+1 as id_max FROM tbl_commande";
$rs_ajout = mysql_query($query_rs_ajout, $conn_panier) or die(mysql_error());
$row_rs_ajout = mysql_fetch_assoc($rs_ajout);
if($row_rs_ajout['id_max'] == '') {
$id = 1;
} else {
$id = $row_rs_ajout['id_max'];
}
$query_ajouter_commande = "INSERT INTO tbl_commande(id_commande, ref_commande, date_commande, mode_paiement, statut_reglement, transport_commande, statut_livraison, ref_livraison, client_id) VALUES
('".$id."',
'C".$date[0].$date[1].$date[2].$date[3].$date[4].$date[5]."',
'".$datebdd."',
'2',
'2',
'".mysql_real_escape_string($_SESSION['panier']['livraison'])."',
'2',
'',
'".mysql_real_escape_string($_SESSION['panier']['client'])."');";
$ajouter_commande = mysql_query($query_ajouter_commande);
echo $query_ajouter_commande;
//On enregistre les articles relatifs à la commande
$nb= count($_SESSION['panier']['id_article']);
$nombre=$nb-1;
for($i=1;$i<=$nombre; $i++) {
$query_rs_ajout2 = "SELECT MAX(id_produit)+1 as id_max2 FROM tbl_commande_produit";
$rs_ajout2 = mysql_query($query_rs_ajout2, $conn_panier) or die(mysql_error());
$row_rs_ajout2 = mysql_fetch_assoc($rs_ajout2);
if($row_rs_ajout2['id_max2'] == '') {
$id2 = 1;
} else {
$id2 = $row_rs_ajout2['id_max2'];
}
$query_rs_tva="SELECT tva_article, prix_article FROM tbl_article WHERE id_article='".$_SESSION['panier']['id_article'][$i]."'";
$rs_tva = mysql_query($query_rs_tva, $conn_panier) or die(mysql_error());
$row_rs_tva = mysql_fetch_assoc($rs_tva);
echo '<br/>'.$query_rs_tva;
$query_ajouter_produit = "INSERT INTO tbl_commande_produit(id_produit, ref_produit, qte_produit, prix_produit, tva_produit, commande_id) VALUES
('".$id2."',
'".mysql_real_escape_string($_SESSION['panier']['id_article'][$i])."',
'".mysql_real_escape_string($_SESSION['panier']['qte'][$i])."',
'".mysql_real_escape_string($row_rs_tva['prix_article'])."',
'".mysql_real_escape_string($row_rs_tva['tva_article'])."',
'".$id."');";
$ajouter_produit = mysql_query($query_ajouter_produit);
}
echo '<br/>'.$query_ajouter_produit;
echo '<br/>'.$_SESSION['panier']['reglement'];
?>
<!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" xml:lang="fr" lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Paiement par chèque</title>
<meta name=""/>
<meta name="Keywords" content=""/>
<link href="" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="global">
<p>Vous avez choisi un mode de règlement par chèque.</p>
<p>Vous voudrez bien nous l'envoyer à l'adresse suivante <b>adresse</b> avec pour libellé : et pour montant: <b><?php echo $_SESSION['panier']['reglement'].' €';?></b></p>
</div>
</body>
</html>
[/php]
Si je met un exit(); à la fin de mes deux requêtes, juste avant le doctype, tout se passe bien.
Un peu étrange je trouve mais certainement pas inexplicable.