Bonjour à tous et à toutes,
Je viens vous demander de l'aide aujourd'hui pour une erreur sql incompréhensible.
Après le payement du panier et le retour sur mon site je fais tout un tas de chose notamment enregistrer la commande dans ma bdd.
Tous va bien sauf si je veut supprimer les produit du panier après l'insertion de la commande.
Voici les requêtes
Code : 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
30
31
32
33
34
 
<?php
$vads_trans_date = strftime('%Y-%m-%d %H:%M:%S');
				$enrg_com = $bdd->prepare('INSERT INTO odl_commandes (ref_commande,id_membre,total_prod_ht_initial, total_prod_ht,total_prod_ttc_initial, total_prod_ttc,livraison_ht, livraison_ttc,tot_gen_ht_initial,tot_gen_ttc_initial, pourcentage_promo, reduction_ht,reduction_ttc, tot_gen_ht, tot_gen_ttc, time, moyen_paiement, adresse_liv_num) VALUES(:num_transaction,:id_utilisateur,:total_prodht_ini,:tot_ht,:total_prodttc_init,:tot_ttc,:tarif_liv_ht,
				:tarif_liv_ttc,:tot_genht_ini,:tot_genttc_ini,:pour_promo,:remise_promo_ht,:remise_promo_ttc,
				:gen_ht,:gen_ttc,:vads_trans_date,:type_paiement,:num_adresse)');
				$enrg_com->bindValue('num_transaction', $transaction_num, PDO::PARAM_INT);
				$enrg_com->bindValue('id_utilisateur', $vads_cust_id, PDO::PARAM_INT);
				$enrg_com->bindValue('total_prodht_ini', $tot_ht_ini, PDO::PARAM_STR);
				$enrg_com->bindValue('tot_ht', $tot_ht, PDO::PARAM_STR);
				$enrg_com->bindValue('total_prodttc_init', $tot_ttc_ini, PDO::PARAM_STR);
				$enrg_com->bindValue('tot_ttc', $tot_ttc, PDO::PARAM_STR);
				$enrg_com->bindValue('tarif_liv_ht', $tarif_livraison_ht, PDO::PARAM_STR);
				$enrg_com->bindValue('tarif_liv_ttc', $tarif_livraison_ttc, PDO::PARAM_STR);
				$enrg_com->bindValue('tot_genht_ini', $total_gen_ht_ini, PDO::PARAM_STR);
				$enrg_com->bindValue('tot_genttc_ini', $total_gen_ttc_ini, PDO::PARAM_STR);
				$enrg_com->bindValue('pour_promo', $promo, PDO::PARAM_STR);
				$enrg_com->bindValue('remise_promo_ht', $remise_promo_ht, PDO::PARAM_STR);
				$enrg_com->bindValue('remise_promo_ttc', $remise_promo, PDO::PARAM_STR);
				$enrg_com->bindValue('gen_ht', $total_gen_ht, PDO::PARAM_STR);
				$enrg_com->bindValue('gen_ttc', $total_gen_ttc, PDO::PARAM_STR);
				$enrg_com->bindValue('vads_trans_date', $vads_trans_date, PDO::PARAM_STR);
				$enrg_com->bindValue('type_paiement', $type_paiement, PDO::PARAM_STR);
				$enrg_com->bindValue('num_adresse', $num_adresse, PDO::PARAM_INT);
				try {
						$enrg_com->execute();
						$num_commande = $bdd->lastInsertId();
						echo 'INSERT odl_commandes OK '.$transaction_num.'';
					}
				catch (PDOException $e) {
						echo 'Error : ' . $e->getMessage();
						echo 'INSERT INTO odl_commandes $transaction_num '.$transaction_num.'';
						exit();
					}?>
Si je met que ça tous va bien.
Si je rajoute ça
Code : 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
 
<?php
$sql = "DELETE FROM odl_commandes_en_cours WHERE id_membre = :id_utilisateur";
				$stmt = $bdd->prepare($sql);
				$stmt->bindParam(':id_utilisateur', $vads_cust_id, PDO::PARAM_INT); 
				try
					{
						$stmt->execute();
					}
				catch ( Exception $e )
					{
						echo'Un problème est survenu DELETE FROM odl_commandes_en_cours';
						echo 'Erreur : '.$e->getMessage().'<br />';
						echo 'Num° : '.$e->getCode();
						$bdd->rollback();
						exit();
					}
				$stmt->CloseCursor();
Voici l'erreur
Error : SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'ref_commande' cannot be null
Je sais bien ce que ça veut dire mais je comprend pas pourquoi dans la mesure ou tous s'enregistre quand même dans la bdd.
Qui pourrait me dire pourquoi ?
Merci d'avance.