Bonjour,

J'ai un problème pour insérer la commande dans sql quand le panier est validé :

Code PHP : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
<?php
	foreach($_SESSION["shopping_cart"] as $keys => $values)
	{
			echo "<tr><td>".$values["product_quantity"]."</td>";
			echo "<td>".$values["product_name"]."</td>";
			echo "<td>".number_format($values["product_price"] * $values["product_quantity"], 2)."</td></tr>";
 
			$total_price = $total_price + ($values["product_quantity"] * $values["product_price"]);
			$total_item = $total_item + ($values["product_quantity"]);
	}
	echo "<tr> <td></td><td></td><td align='center'><br>Total : ".number_format($total_price, 2)."</td></tr>";
?>

J'ai une table Commande

idcommande, datecommande, jourcommande, numerocommande, delaicommande, etatcommande, payecommande, nomcommande, telcommande, adressecommande, villecommande

et une table lignecommande.

idlignecommande, idcommande, ligneproduit, lignequantite, ligneprix


J'étais parti sur un truc du genre :

Code PHP : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
 'INSERT INTO commande (datecommande, jourcommande,	numerocommande,	delaicommande, etatcommande, payecommande, nomcommande,	telcommande, adressecommande, villecommande)
VALUES ("datecommande", "jourcommande",	"numerocommande", "delaicommande", "etatcommande", "payecommande", "nomcommande",	"telcommande", "adressecommande", "villecommande");
 SET @a = LAST_INSERT_idcommande();
	INSERT INTO details_commande (idcommande, ligneproduit, lignequantite, ligneprix)
VALUES ("@a","ligneproduit","lignequantite","ligneprix")';

Mais quand je prépare ma requete, cela ne fonctionne pas du tout.

Code PHP : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  require_once('dbconn.php');
  $result = 0;
 
  $datecommande  = trim($_POST["datecommande"]);
  $numerocommande  = trim($_POST["numerocommande"]);
  $delaicommande  = trim($_POST["delaicommande"]);
  $etatcommande  = trim($_POST["etatcommande"]);
  $payecommande  = trim($_POST["payecommande"]);
  $nomcommande  = trim($_POST["nomcommande"]);
  $telcommande  = trim($_POST["telcommande"]);
  $adressecommande    = trim($_POST["adressecommande"]);
  $villecommande = trim($_POST["villecommande]);
//prepare sql and bind parameters
   $stmt = $dbconn->prepare("INSERT INTO commande(datecommande, jourcommande,	numerocommande,	delaicommande, etatcommande, payecommande, nomcommande,	telcommande, adressecommande, villecommande) VALUES (:datecommande, :jourcommande, :numerocommande, :delaicommande,:etatcommande, :payecommande, :nomcommande,	:telcommande, :adressecommande, :villecommande)");
 
    $stmt->bindParam(':datecommande', $datecommande);
	$stmt->bindParam(':numerocommande', $numerocommande);
	$stmt->bindParam(':delaicommande', $delaicommande);
	$stmt->bindParam(':etatcommande', $etatcommande);
	$stmt->bindParam(':payecommande', $payecommande);
	$stmt->bindParam(':nomcommande', $nomcommande);
	$stmt->bindParam(':telcommande', $telcommande);
	$stmt->bindParam(':adressecommande', $adressecommande);
	$stmt->bindParam(':villecommande', $villecommande);
    // insert a row
    if($stmt->execute()){
      $result =1;
    }
    echo $result;

Merci,