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

Langage PHP Discussion :

insertion donnée dans 4 tables, mais une seule insertion fonctionne [PHP 5.4]


Sujet :

Langage PHP

  1. #1
    Membre régulier
    Femme Profil pro
    Webdesigner
    Inscrit en
    Juin 2014
    Messages
    176
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 37
    Localisation : Belgique

    Informations professionnelles :
    Activité : Webdesigner

    Informations forums :
    Inscription : Juin 2014
    Messages : 176
    Points : 74
    Points
    74
    Par défaut insertion donnée dans 4 tables, mais une seule insertion fonctionne
    bonjour,
    j'ai un soucis avec mon formulaire, j'aimerais insérer plusieurs données dans 4 tables : offre_de_prix,clients,commentaires et projet.
    Seule l'insertion dans ma table clients fonctionne...

    mon formulaire:
    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
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    $sql=$bdd->prepare('SELECT offre_de_prix.offreNumero,offre_de_prix.offreDate, offre_de_prix.offreFinDate, offre_de_prix.offreNomClient,clients.clientRemise,produits.produitRef,produits.produitPu,produits.produitDescription,categorie.categorieNom,projet.projetNom,commentaires.commentaireNom,offre_de_prix.offreQuantite,offre_de_prix.offreTotal,clients.clientNumero FROM offre_de_prix, clients, produits, categorie, projet, commentaires WHERE offre_de_prix.clientID=clients.clientID AND projet.clientID=clients.clientID ORDER BY offreNumero DESC LIMIT 1');
    $reslt=$sql->execute();
    $row = $sql->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT);
     
    echo '<div class="form_inscription">';
    echo'<h3>formulaire d\'offres de prix, inscription :</h3>';
    echo'<form action="" method="post">';
    echo'<label>numéro de l\'offre:</label>';
    echo"<input type='text' name='offreNumero' value='$row[0]'>";
    echo'<br>';
    echo'<label>date de l\'offre :</label>';
    echo"<input type='date' name='offreDate' value='$row[1]'>";
    echo'<br>';
    echo'<label>fin de l\'offre : </label>';
    echo"<input type='date' name='offreFinDate' value='$row[2]'>";
    echo'<br>';
    echo'<label for="clientNom">nom du client:</label>';
    echo"<input id='clientNom' type='text' name='clientNom' value='$row[3]'>";
    echo'<br>';
    echo'<label>numero du client:</label>';
    echo"<input type='text' name='clientNumero' value='$row[13]'>";
    echo'<br>';
    echo'<label>Projet :</label>';
    echo"<input type='text' name='projetNom' value='$row[9]'>";
    echo'<br>';
    echo'<label>Remise Client :</label>';
    echo"<input type='number' name='clientRemise' value='$row[4]'>%";
    echo'<br>';
    echo '<label>Référence du produit : </label>';
    echo"<input type='text' name='produitRef' value='$row[5]'>";
    echo'<br>';
    echo'<label>Catégorie du produit :</label>';
    echo"<input type='text' name='categorieNom' value='$row[8]'>";
    echo'<br>';
    echo'<label>Description : </label>';
    echo"<input type='text' name='produitDescription' value='$row[7]'>";
    echo'<br>';
    echo'<label>Quantité : </label>';
    echo"<input type='text' name='offreQuantite' value='$row[11]'>";
    echo'<br>';
    echo'<label>P.U : </label>';
    echo"<input type='number' name='produitPu' value='$row[6]'>";
    echo'<br>';
    echo'<label>Commentaires : </label>';
    echo"<input type='text' name='commentaireNom' value='$row[10]'>";
    echo'<br>';
    echo'<label>Total :</label>';
        $quantite='' ;
        $PU=$row[6];
        $offreNumero2=$row[0];
        $TOTAL_SUM=$quantite*$PU;
    echo"<input for='total'  type='text' name='offreTotal' value='$TOTAL_SUM'>";
    echo'<br>';
     
     
    echo'<input  type="submit" name="Envoyer" value="Envoyer">';
    echo'&nbsp;';
    echo'<input  type="submit" name="Modifier" value="Mise à jour">';
    echo'&nbsp;';
    echo'<input  type="submit" name="enregistrer" value="Enregistrer le pdf">';
     
    echo'</form>';
    echo'</div>';
    mon script:
    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
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    if(isset($_POST['Envoyer'])) {
     
     
        $objet = new stdClass();
     
        $objet->offreNumero = $_POST["offreNumero"];//1
        $objet->offreDate = $_POST["offreDate"];//2
        $objet->offreFinDate = $_POST["offreFinDate"];//3
        $objet->clientNom = $_POST["clientNom"];//4
        $objet->clientNumero = $_POST["clientNumero"];//4
        $objet->projetNom = $_POST["projetNom"];//5
        $objet->offreQuantite = $_POST['offreQuantite'];//9
        $objet->clientRemise = $_POST["clientRemise"];//1
        $objet->commentaireNom = $_POST["commentaireNom"];//12
        $objet->offreTotal = $_POST['offreTotal'];//13
     
     
        $valid = v::attribute('offreNumero', v::alnum()->notEmpty()->setName('numero'))
            ->attribute('clientNom', v::alpha()->notEmpty()->setName('Nom'))
            ->attribute('clientNumero', v::alnum()->notEmpty()->setName('clientNumero'))
            ->attribute('projetNom', v::alpha()->notEmpty()->setName('projetNom'))
            ->attribute('offreTotal', v::numeric()->notEmpty()->setName('total'))
            ->attribute('clientRemise', v::numeric()->notEmpty()->setName('clrem'))
            ->attribute('commentaireNom', v::alnum()->notEmpty()->setName('cmtNom'))
            ->attribute('offreFinDate', v::date()->notEmpty()->setName('date'))
            ->attribute('offreQuantite', v::numeric()->notEmpty()->setName('quantite'))
            ->attribute('offreDate', v::date()->notEmpty()->setName('date'));
     
     
        try {
     
            $valid->assert($objet);
     
    //s'enregistre
            $st_client=$bdd->prepare("INSERT INTO clients (clientRemise,clientNom,clientNumero) VALUES(?,?,?)");
            $st_client->execute(array($objet->clientRemise,$objet->clientNom,$objet->clientNumero));
     
     
    //ne s'enregistre pas
            $st_offre = $bdd->prepare("INSERT INTO offre_de_prix (offreNumero,offreDate,offreFinDate,offreNomClient,offreQuantite,offreTotal)VALUES (?,?,?,?,?,?)");
            $st_offre->execute(array($objet->offreNumero, $objet->offreDate, $objet->offreFinDate,$objet->clientNom,  $objet->offreQuantite, $objet->offreTotal));
     
    //ne s'enregistre pas
            $st_projet = $bdd->prepare("INSERT INTO projet(projetNom) VALUES (?) ");
            $st_projet->execute(array($objet->projetNom));
     
    //ne s'enregistre pas
            $st_commentaire = $bdd->prepare("INSERT INTO commentaires(commentaireNom) VALUES(?)");
            $st_commentaire->execute(array($objet->commentaireNom));
     
     
            header('Refresh: 5; URL=./doc.php?page=Offres_de_prix');
            echo '<p class="p_MAJ_maj" >';
            echo 'Enregistrement effectué, vous allez être redirigé d\'ici quelques secondes...';
            echo '</p>';
     
     
        } catch (\InvalidArgumentException $e) {
     
            $objet->error = $e->findMessages([
                'notEmpty' => '{{name}} veuillez remplir ce champ',
                'alpha' => '{{name}} ne peut contenir que des lettres',
                'alnum' => '{{name}} Que des chiffres et des lettres',
                'numeric' => '{{name}} Que des chiffres',
                'date' => '{{name}} veuillez choisir une autre date',
            ]);
     
            $_SESSION['error'] = $objet->error;
            $_SESSION['data'] = $_POST;
            //header('Refresh: 5; URL=./doc.php?page=Offres_de_prix');
            echo '<p class="p_MAJ_maj" >';
            echo 'erreur ';
            echo '</p>';
     
        }
     
     
    }
    ce que j'ai déjà essayé:
    - try{} catch{} pour chaque INSERT INTO =>ne fonctionne pas sauf toujours pour clients.
    - if(isset($_POST["offreNumero"]) && isset($_POST["clientNom"])) { avant l'insertion =>idem.
    - clause WHERE après chaque INSERT INTO avec offre_de_prix.clientID=clients.clientID(pour offre_de_prix) etc...=>idem

    j'espère que vous pourrez un peu m'aiguiller, car je ne vois pas pourquoi cela ne s'enregistre que dans une seule table et pas les autres...
    merci de votre aide

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Try/catch sert à intercepter les exceptions, ça n'a jamais permis de corriger un bug.
    Active par contre les exceptions PDO pour voir ce qu'il se passe.
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  3. #3
    Membre régulier
    Femme Profil pro
    Webdesigner
    Inscrit en
    Juin 2014
    Messages
    176
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 37
    Localisation : Belgique

    Informations professionnelles :
    Activité : Webdesigner

    Informations forums :
    Inscription : Juin 2014
    Messages : 176
    Points : 74
    Points
    74
    Par défaut
    je le sais bien sabotage...

    Je viens de faire un echo error_reporting(E_ALL); et un echo error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
    cela m'affiche: 32767 et rien d'autre...

    j'ai mit en commentaire l'insertion de la table clients...
    donc s'il y aurait une erreur, mon script devrait m'indiquer : erreur
    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
     catch (\InvalidArgumentException $e) {
     
            $objet->error = $e->findMessages([
                'notEmpty' => '{{name}} veuillez remplir ce champ',
                'alpha' => '{{name}} ne peut contenir que des lettres',
                'alnum' => '{{name}} Que des chiffres et des lettres',
                'numeric' => '{{name}} Que des chiffres',
                'date' => '{{name}} veuillez choisir une autre date',
            ]);
     
            $_SESSION['error'] = $objet->error;
            $_SESSION['data'] = $_POST;
            //header('Refresh: 5; URL=./doc.php?page=Offres_de_prix');
            echo '<p class="p_MAJ_maj" >';
            echo 'erreur ';
            echo '</p>';
     
        }
    Mais au lieu de ça, il m'affiche:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    echo '<p class="p_MAJ_maj" >';
            echo 'Enregistrement effectué, vous allez être redirigé d\'ici quelques secondes...';
            echo '</p>';
    mais rien ne s'est inséré dans mes tables...

  4. #4
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    error_reporting() permet de definir le niveau des erreurs remontés. la fonction retourne ce niveau, c'est tout ; c'est le chiffre que tu obtiens.

    Pour PDO, les erreurs ça se passe comme ça :
    http://php.net/manual/fr/pdo.error-handling.php
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  5. #5
    Membre régulier
    Femme Profil pro
    Webdesigner
    Inscrit en
    Juin 2014
    Messages
    176
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 37
    Localisation : Belgique

    Informations professionnelles :
    Activité : Webdesigner

    Informations forums :
    Inscription : Juin 2014
    Messages : 176
    Points : 74
    Points
    74
    Par défaut
    merci voilà l'erreur:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    PDO::errorCode(): 23000 
    PDOStatement::errorInfo(): 
    Array ( [0] => 23000 [1] => 1452 [2] => Cannot add or update a child row: a foreign key constraint fails (`mc_jung_mod`.`offre_de_prix`, CONSTRAINT `FK_offre_de_prix_clientID` FOREIGN KEY (`clientID`) REFERENCES `clients` (`clientID`)) )
     
    PDO::errorCode(): 23000 
    PDOStatement::errorInfo(): 
    Array ( [0] => 23000 [1] => 1452 [2] => Cannot add or update a child row: a foreign key constraint fails (`mc_jung_mod`.`projet`, CONSTRAINT `FK_projet_clientID` FOREIGN KEY (`clientID`) REFERENCES `clients` (`clientID`)) )
     
    PDO::errorCode(): 23000
    PDOStatement::errorInfo(): Array ( [0] => 23000 [1] => 1452 [2] => Cannot add or update a child row: a foreign key constraint fails (`mc_jung_mod`.`commentaires`, CONSTRAINT `FK_commentaires_offreId` FOREIGN KEY (`offreId`) REFERENCES `offre_de_prix` (`offreId`)) )

  6. #6
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    C'est gentil de nous fournir les erreurs, tu pouvais les analyser aussi

    Dans ta table offre_de_prix, tu as une reférence à clientID, cette colonne n'apparait pas dans ton insertion ... c'est embêtant. La colonne nomClient n'a par contre rien à faire là.
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  7. #7
    Membre régulier
    Femme Profil pro
    Webdesigner
    Inscrit en
    Juin 2014
    Messages
    176
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 37
    Localisation : Belgique

    Informations professionnelles :
    Activité : Webdesigner

    Informations forums :
    Inscription : Juin 2014
    Messages : 176
    Points : 74
    Points
    74
    Par défaut
    je l'avais analysée, j'avais compris que c'est clientId qui posait problème ainsi que pour la table commentaire c'est l'offreId...
    j'étais en train de me poser la question comment ajouter le clientID ^^

    dans ma table offre j'ai un champ qui se nomme offreNomClient et l'une de mes variables contient le nom de ce client, sinon j'ai un trou lors de l'insertion...

    donc je dois mettre $objet->clientID=$row[...] (repris dans mon SELECT plus haut (dont lclientId je dois l'y mettre) dans mon script et ensuite je l'y insère) si je comprend bien?

  8. #8
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Pourquoi tu as le nom du client en plus de l'id dans la table offre ?
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  9. #9
    Membre régulier
    Femme Profil pro
    Webdesigner
    Inscrit en
    Juin 2014
    Messages
    176
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 37
    Localisation : Belgique

    Informations professionnelles :
    Activité : Webdesigner

    Informations forums :
    Inscription : Juin 2014
    Messages : 176
    Points : 74
    Points
    74
    Par défaut
    plus j'y pense et plus c'est vrai que c'est idiot ^^

    bon voilà j'ai réussi:
    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
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    $objet = new stdClass();
     
     
        $objet->offreNumero = $_POST["offreNumero"];//1
        $objet->offreDate = $_POST["offreDate"];//2
        $objet->offreFinDate = $_POST["offreFinDate"];//3
        $objet->clientNom = $_POST["clientNom"];//4
        $objet->clientNumero = $_POST["clientNumero"];//4
        $objet->projetNom = $_POST["projetNom"];//5
        $objet->offreQuantite = $_POST['offreQuantite'];//9
        $objet->clientRemise = $_POST["clientRemise"];//1
        $objet->commentaireNom = $_POST["commentaireNom"];//12
        $objet->offreTotal = $_POST['offreTotal'];//13
     
     
        $valid = v::attribute('offreNumero', v::alnum()->notEmpty()->setName('numero'))
            ->attribute('clientNom', v::alpha()->notEmpty()->setName('Nom'))
            ->attribute('clientNumero', v::alnum()->notEmpty()->setName('clientNumero'))
            ->attribute('projetNom', v::alpha()->notEmpty()->setName('projetNom'))
            ->attribute('offreTotal', v::numeric()->notEmpty()->setName('total'))
            ->attribute('clientRemise', v::numeric()->notEmpty()->setName('clrem'))
            ->attribute('commentaireNom', v::alnum()->notEmpty()->setName('cmtNom'))
            ->attribute('offreFinDate', v::date()->notEmpty()->setName('date'))
            ->attribute('offreQuantite', v::numeric()->notEmpty()->setName('quantite'))
            ->attribute('offreDate', v::date()->notEmpty()->setName('date'));
     
     
     
    try{
            $valid->assert($objet);
     
            $st_client = $bdd->prepare("INSERT INTO clients (clientRemise,clientNom,clientNumero) VALUES(?,?,?)");
            $st_client->execute(array($objet->clientRemise, $objet->clientNom, $objet->clientNumero));
     
     
        $st_offre1=$bdd->prepare("SELECT clients.clientID,offre_de_prix.offreID FROM clients,offre_de_prix ORDER BY clientNom DESC LIMIT 1 ");
        $resultat_offre=$st_offre1->execute();
        $row = $st_offre1->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT);
        $objet->clientID =$row[0];
        $objet->offreID=$row[1];
     
     
            $st_offre = $bdd->prepare("INSERT INTO offre_de_prix (offreNumero,offreDate,offreFinDate,offreNomClient,offreQuantite,offreTotal,clientID)VALUES (?,?,?,?,?,?,?)");
            $st_offre->execute(array($objet->offreNumero, $objet->offreDate, $objet->offreFinDate,$objet->clientNom,  $objet->offreQuantite, $objet->offreTotal,$objet->clientID));
            /*echo "\nPDO::errorCode(): ", $st_offre->errorCode();
            echo "\nPDOStatement::errorInfo():\n";
            $arr = $st_offre->errorInfo();
            print_r($arr);*/
     
     
            $st_projet = $bdd->prepare("INSERT INTO projet(projetNom,clientID) VALUES (?,?) ");
            $st_projet->execute(array($objet->projetNom,$objet->clientID));
            /*echo "\nPDO::errorCode(): ", $st_projet->errorCode();
            echo "\nPDOStatement::errorInfo():\n";
            $arr = $st_projet->errorInfo();
            print_r($arr);*/
     
     
     
            $st_commentaire = $bdd->prepare("INSERT INTO commentaires(commentaireNom,offreID) VALUES(?,?)");
            $st_commentaire->execute(array($objet->commentaireNom,$objet->offreID));
            /*echo "\nPDO::errorCode(): ", $st_commentaire->errorCode();
            echo "\nPDOStatement::errorInfo():\n";
            $arr = $st_commentaire->errorInfo();
            print_r($arr);*/
     
     
            //header('Refresh: 5; URL=./doc.php?page=Offres_de_prix');
            echo '<p class="p_MAJ_maj" >';
            echo 'Enregistrement effectué, vous allez être redirigé d\'ici quelques secondes...';
            echo '</p>';
     
     
        } catch(\InvalidArgumentException $e) {
     
            $objet->error = $e->findMessages([
                'notEmpty' => '{{name}} veuillez remplir ce champ',
                'alpha' => '{{name}} ne peut contenir que des lettres',
                'alnum' => '{{name}} Que des chiffres et des lettres',
                'numeric' => '{{name}} Que des chiffres',
                'date' => '{{name}} veuillez choisir une autre date',
            ]);
     
            $_SESSION['error'] = $objet->error;
            $_SESSION['data'] = $_POST;
            //header('Refresh: 5; URL=./doc.php?page=Offres_de_prix');
            echo '<p class="p_MAJ_maj" >';
            echo 'erreur ';
            echo '</p>';
     
        }
    mais mon soucis maintenant c'est quand je lui demande le SELECT avec le 'nouvel id du client' pour les autres table, il m'insère l'ancien clientID...
    un ami me dit de chercher du coté de lastInsertID...

    la dernière fois que j'ai utilisé lastInsertId, ca ne marchait plus

  10. #10
    Membre régulier
    Femme Profil pro
    Webdesigner
    Inscrit en
    Juin 2014
    Messages
    176
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 37
    Localisation : Belgique

    Informations professionnelles :
    Activité : Webdesigner

    Informations forums :
    Inscription : Juin 2014
    Messages : 176
    Points : 74
    Points
    74
    Par défaut
    Voilà c'est résolu
    voici mon code pour ceux que cela intéresserait :
    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
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
     $objet = new stdClass();
     
        $objet->clientNom = $_POST["clientNom"];//4
        $objet->clientNumero = $_POST["clientNumero"];//4
        $objet->clientRemise = $_POST["clientRemise"];//1
     
        $valid = v::attribute('clientNom', v::alpha()->notEmpty()->setName('Nom'))
            ->attribute('clientNumero', v::alnum()->notEmpty()->setName('clientNumero'))
            ->attribute('clientRemise', v::numeric()->notEmpty()->setName('clrem'));
     
     
     
    try {
        $valid->assert($objet);
     
        $st_client = $bdd->prepare("INSERT INTO clients (clientRemise,clientNom,clientNumero) VALUES(?,?,?)");
        $st_client->execute(array($objet->clientRemise, $objet->clientNom, $objet->clientNumero));
    }catch(\InvalidArgumentException $e) {
     
        $objet->error = $e->findMessages([
            'notEmpty' => '{{name}} veuillez remplir ce champ',
            'alpha' => '{{name}} ne peut contenir que des lettres',
            'alnum' => '{{name}} Que des chiffres et des lettres',
            'numeric' => '{{name}} Que des chiffres',
     
        ]);
     
        $_SESSION['error'] = $objet->error;
        $_SESSION['data'] = $_POST;
        header('Refresh: 5; URL=./doc.php?page=Offres_de_prix');
        echo '<p class="p_MAJ_maj" >';
        echo 'erreur ';
        echo '</p>';}
     
     
    $objet = new stdClass();
     
    $objet->offreNumero = $_POST["offreNumero"];//1
        $objet->offreDate = $_POST["offreDate"];//2
        $objet->offreFinDate = $_POST["offreFinDate"];
        $objet->projetNom = $_POST["projetNom"];//5
        $objet->offreQuantite = $_POST['offreQuantite'];//9
        $objet->offreTotal = $_POST['offreTotal'];//13
     
        $valid = v::attribute('offreNumero', v::alnum()->notEmpty()->setName('numero'))
            ->attribute('projetNom', v::alpha()->notEmpty()->setName('projetNom'))
            ->attribute('offreTotal', v::numeric()->notEmpty()->setName('total'))
            ->attribute('offreFinDate', v::date()->notEmpty()->setName('date'))
            ->attribute('offreQuantite', v::numeric()->notEmpty()->setName('quantite'))
            ->attribute('offreDate', v::date()->notEmpty()->setName('date'));
    try{
     
        $st_offre1=$bdd->prepare("SELECT clients.clientID FROM clients ORDER BY clientNom DESC LIMIT 1 ");
        $resultat_offre=$st_offre1->execute();
        $row = $st_offre1->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT);
        $objet->clientID =$row[0];
     
     
     
            $st_offre = $bdd->prepare("INSERT INTO offre_de_prix (offreNumero,offreDate,offreFinDate,offreQuantite,offreTotal,clientID)VALUES (?,?,?,?,?,?)");
            $st_offre->execute(array($objet->offreNumero, $objet->offreDate, $objet->offreFinDate, $objet->offreQuantite, $objet->offreTotal,$objet->clientID));
            /*echo "\nPDO::errorCode(): ", $st_offre->errorCode();
            echo "\nPDOStatement::errorInfo():\n";
            $arr = $st_offre->errorInfo();
            print_r($arr);*/
     
     
            $st_projet = $bdd->prepare("INSERT INTO projet(projetNom,clientID) VALUES (?,?) ");
            $st_projet->execute(array($objet->projetNom,$objet->clientID));
            /*echo "\nPDO::errorCode(): ", $st_projet->errorCode();
            echo "\nPDOStatement::errorInfo():\n";
            $arr = $st_projet->errorInfo();
            print_r($arr);*/
     
    } catch(\InvalidArgumentException $e) {
     
        $objet->error = $e->findMessages([
            'notEmpty' => '{{name}} veuillez remplir ce champ',
            'alpha' => '{{name}} ne peut contenir que des lettres',
            'alnum' => '{{name}} Que des chiffres et des lettres',
            'numeric' => '{{name}} Que des chiffres',
            'date' => '{{name}} veuillez choisir une autre date',
        ]);
     
        $_SESSION['error'] = $objet->error;
        $_SESSION['data'] = $_POST;
        header('Refresh: 5; URL=./doc.php?page=Offres_de_prix');
        echo '<p class="p_MAJ_maj" >';
        echo 'erreur ';
        echo '</p>';
     
    }
        $objet = new stdClass();
     
        $objet->commentaireNom = $_POST["commentaireNom"];//12
     
        $valid = v::attribute('commentaireNom', v::alnum()->notEmpty()->setName('cmtNom'));
     
    try{
        $st_commentaire1=$bdd->prepare("SELECT offre_de_prix.offreID FROM offre_de_prix ORDER BY offreNumero DESC LIMIT 1 ");
        $resultat_commentaire=$st_commentaire1->execute();
        $row = $st_commentaire1->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT);
        $objet->offreID =$row[0];
     
            $st_commentaire = $bdd->prepare("INSERT INTO commentaires(commentaireNom,offreID) VALUES(?,?)");
            $st_commentaire->execute(array($objet->commentaireNom,$objet->offreID));
            /*echo "\nPDO::errorCode(): ", $st_commentaire->errorCode();
            echo "\nPDOStatement::errorInfo():\n";
            $arr = $st_commentaire->errorInfo();
            print_r($arr);*/
     
     
            header('Refresh: 5; URL=./doc.php?page=Offres_de_prix');
            echo '<p class="p_MAJ_maj" >';
            echo 'Enregistrement effectué, vous allez être redirigé d\'ici quelques secondes...';
            echo '</p>';
     
     
        } catch(\InvalidArgumentException $e) {
     
            $objet->error = $e->findMessages([
                'notEmpty' => '{{name}} veuillez remplir ce champ',
                'alnum' => '{{name}} Que des chiffres et des lettres',
     
            ]);
     
            $_SESSION['error'] = $objet->error;
            $_SESSION['data'] = $_POST;
            header('Refresh: 5; URL=./doc.php?page=Offres_de_prix');
            echo '<p class="p_MAJ_maj" >';
            echo 'erreur ';
            echo '</p>';
     
        }
    donc j'insère d'abord mes données dans ma table client
    ensuite j'insère les données suivante dans ma table offre et projet avec ID du client qui leur correspond
    et pour finir j'insère mes données restante dans ma table commentaires avec l'ID de l'offre qui correspond

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [MySQL] Problème insertion données dans la table
    Par michgoarin dans le forum PHP & Base de données
    Réponses: 1
    Dernier message: 28/12/2014, 00h08
  2. [WD17] Affichage données dans combo table d'une Zone Répété
    Par Xipotera dans le forum WinDev
    Réponses: 1
    Dernier message: 10/08/2012, 16h49
  3. [WD12E] Afficher les données dans la table d'une requête
    Par melchi dans le forum WinDev
    Réponses: 2
    Dernier message: 12/08/2009, 09h07
  4. Réponses: 18
    Dernier message: 26/07/2006, 14h51
  5. Réponses: 4
    Dernier message: 08/06/2006, 20h06

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