IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PHP & Base de données Discussion :

erreur sql incompréhensible


Sujet :

PHP & Base de données

  1. #1
    Membre régulier
    Homme Profil pro
    Educateur spécialisé
    Inscrit en
    Janvier 2012
    Messages
    208
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Educateur spécialisé
    Secteur : Santé

    Informations forums :
    Inscription : Janvier 2012
    Messages : 208
    Points : 118
    Points
    118
    Par défaut erreur sql incompréhensible
    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.

  2. #2
    Expert éminent
    Avatar de Séb.
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    5 098
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 098
    Points : 8 207
    Points
    8 207
    Billets dans le blog
    17
    Par défaut
    Quelle requête provoque cela exactement ?

    Tu as des clefs étrangères ?

    Tu fais une manip qui fausse l'intégrité référentielle => Tu enregistres une valeur à NULL alors qu'elle ne devrait pas l'être ou tu supprimes une ligne dont le ON DELETE SET NULL provoquerait l'anomalie

    Colle-nous les SHOW CREATE TABLE ta_table de tes tables.
    Un problème exposé clairement est déjà à moitié résolu
    Keep It Smart and Simple

  3. #3
    Membre régulier
    Homme Profil pro
    Educateur spécialisé
    Inscrit en
    Janvier 2012
    Messages
    208
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Educateur spécialisé
    Secteur : Santé

    Informations forums :
    Inscription : Janvier 2012
    Messages : 208
    Points : 118
    Points
    118
    Par défaut
    Bonjour Séb et merci pour ton aide.
    C'est la requête DELETE qui provoque une erreur sur le requête INSERT
    Il n'y a aucune valeurs vide, toute les valeurs sont enregistrées dans les colonnes avec ou sans l'erreur.
    Le truc c'est que si j’enlève la requête DELETE il n'y a pas d'erreur et si je la met il y a l'erreur met rien ne change au niveau de l'insertion.

    EDIT :
    Je pense que ça vient du rollback
    $bdd->rollback();

    RE EDIT :
    C'est pas ça.

  4. #4
    Expert éminent
    Avatar de Séb.
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    5 098
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 098
    Points : 8 207
    Points
    8 207
    Billets dans le blog
    17
    Par défaut
    Je ne vois pas comment un DELETE peut provoquer une erreur sur un INSERT.

    Doit y avoir une clef entre odl_commandes et odl_commandes_en_cours qui bloque
    Un problème exposé clairement est déjà à moitié résolu
    Keep It Smart and Simple

  5. #5
    Membre régulier
    Homme Profil pro
    Educateur spécialisé
    Inscrit en
    Janvier 2012
    Messages
    208
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Educateur spécialisé
    Secteur : Santé

    Informations forums :
    Inscription : Janvier 2012
    Messages : 208
    Points : 118
    Points
    118
    Par défaut
    Voici les requêtes, je vois pas pourquoi ça déconne.
    En plus j'utilise le même code pour les retours de payement via paypal et les virements et tout fonctionne.
    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
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    $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, payment_status, num_carte, 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,:status,:carte_num,: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', $vads_card_brand, PDO::PARAM_STR);
    				$enrg_com->bindValue('status', $status, PDO::PARAM_STR);
    				$enrg_com->bindValue('carte_num', $vads_card_number, PDO::PARAM_STR);
    				$enrg_com->bindValue('num_adresse', $num_adresse, PDO::PARAM_INT);
    				try {
    						$enrg_com->execute();
    						$num_commande = $bdd->lastInsertId();
    						echo 'odl_commandes OK '.$transaction_num.'';
    					}
    				catch (PDOException $e) {
    						echo'Un problème est survenu INSERT INTO odl_commandes';
    						echo 'Erreur : '.$e->getMessage().'<br />';
    						echo 'Num° : '.$e->getCode();
    						exit();
    					}
    				$enrg_com->closeCursor();
    				$sql = "DELETE FROM odl_commandes_en_cours WHERE id_membre = :id_client";
    				$stmt = $bdd->prepare($sql);
    				$stmt->bindParam(':id_client', $vads_cust_id, PDO::PARAM_INT); 
    				try
    					{
    						$stmt->execute();
    					}
    				catch ( Exception $err )
    					{
    						echo'Un problème est survenu DELETE FROM odl_commandes_en_cours';
    						echo 'Erreur : '.$err->getMessage().'<br />';
    						echo 'Num° : '.$err->getCode();
    						exit();
    					}
    				$stmt->CloseCursor();
    Voici l'erreur
    Un problème est survenu INSERT INTO odl_commandes
    Erreur : SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'ref_commande' cannot be null
    Num° : 23000

Discussions similaires

  1. [MySQL] Erreur SQL incompréhensible
    Par Spaccio dans le forum PHP & Base de données
    Réponses: 5
    Dernier message: 29/05/2011, 04h32
  2. [ODBC] erreur SQL pour les unions qui renvoient vide
    Par fabriceMerc dans le forum MS SQL Server
    Réponses: 3
    Dernier message: 25/11/2003, 11h06
  3. Erreurs SQL Server
    Par ZuZu dans le forum MS SQL Server
    Réponses: 5
    Dernier message: 09/10/2003, 16h23
  4. erreur SQL ...INSERT INTO
    Par naidinp dans le forum ASP
    Réponses: 20
    Dernier message: 18/09/2003, 11h38
  5. erreur sql loader et performance
    Par mobisky dans le forum SQL*Loader
    Réponses: 14
    Dernier message: 20/08/2003, 12h27

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo