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 :

récupération d'un id


Sujet :

PHP & Base de données

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Femme Profil pro
    Développeur Web
    Inscrit en
    Juin 2017
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 31
    Localisation : France, Mayenne (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Juin 2017
    Messages : 17
    Par défaut récupération d'un id
    Bonjour a toute et a tous j'ai un petit problème qui me bloque depuis 2 jours et voudrais savoir comment régler ce problème.
    Alors le problème c'est que j'ai une recherche dynamique de mes clients et que je n'arrive pas a récupéré l'id du client que j'ai sélectionné pour l'enregistrer en base de donnée. La particularité c'est qu'il y a 2 bases de données 1 ou il y a tout le facturier de la personne pour qui je travail et l'autre ou il y a mes ticket qui y seront enregistrer . Et mon problème c'est que je n'arrive pas a faire le lien entre les 2 bases de données. J'espère que vous pourrez m'aider parce que la je suis complètement bloquer.
    Voici le code ou je fais ma recherche dynamique :
    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
     
    <?php
    include("config.php");
    $keyword = $_POST['data'];
        $sql = "select * from ".$db_table." where ".$db_column." like '".$keyword."%' or ".$db_column2." like '".$keyword."%' or ".$db_column3." like '".$keyword."%'limit 0,20";
    //$sql = "select name from ".$db_table."";
    $result = mysql_query($sql) or die(mysql_error());
    if(mysql_num_rows($result))
    {
        echo '<ul class="list">';
        while($row = mysql_fetch_array($result))
        {
            $str = strtolower($row['nom']);
            $start = strpos($str,$keyword);
            $end   = similar_text($str,$keyword);
            $last = substr($str,$end,strlen($str));
            $first = substr($str,$start,$end);
     
            $str2 = strtolower($row['prenom']);
            $start2 = strpos($str2,$keyword);
            $end2   = similar_text($str2,$keyword);
            $last2 = substr($str2,$end2,strlen($str2));
            $first2 = substr($str2,$start2,$end2);
     
            $str3 = strtolower($row['email']);
            $start3 = strpos($str3,1);
            $end3   = similar_text($str3,$keyword);
            $last3 = substr($str3,$end3,strlen($str3));
            $first3 = substr($str3,$start3,$end3);
     
            $str4 = strtolower($row['adresse']);
            $start4 = strpos($str4,$keyword);
            $end4   = similar_text($str4,$keyword);
            $last4= substr($str4,$end4,strlen($str4));
            $first4 = substr($str4,$start4,$end4);
     
            $str5 = strtolower($row['ville']);
            $start5 = strpos($str5,$keyword);
            $end5   = similar_text($str5,$keyword);
            $last5 = substr($str5,$end5,strlen($str5));
            $first5 = substr($str5,$start5,$end5);
     
            $idclient = strtolower($row['idclient']);
            $start6 = strpos($idclient,$keyword);
            $end6   = similar_text($idclient,$keyword);
            $last6 = substr($idclient,$end6,strlen($idclient));
            $first6 = substr($idclient,$start6,$end6);
     
            $final = '<span class="bold">'.$first.'</span>'.$last;
            $final2 = '<span class="bold">'.$first2.'</span>'.$last2;
            $final3 = '<span class="mail">'.$first3.'</span><span class="mail">'.$last3.'</span>';
            $final4 = '<span class="adresse">'.$first4.'</span><span class="adresse">'.$last4.',</span>';
            $final5 = '<span class="adresse">'.$first5.'</span><span class="adresse">'.$last5.'</span>';
            $final6 = '<span class="adresse">'.$first6.'</span><span class="adresse">'.$last6.'</span>';
            echo '<li><a href=\'javascript:void(0);\'>'.$final.' '.$final2.' <br>'.$final3.' <br>'.$final4.' '.$final5.'<br>'. $final6 .'</a></li>';
        }
        echo "</ul>";
    }
    else
        echo "client non trouvé";
    ?>
    et le code ou y a le formulaire et le php
    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
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
     
    <?php
     
    include("../inc/fonctions.php");
    include('index.php');
     
    $bddtest = new PDO("mysql:host=localhost;dbname=projet-facturier", "root","root");
    $bddtest->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    if (isset($_POST["submit"])) {
     
    //récupère les données qui ont été saisie dans le formulaire
        $probleme = !empty($_POST['probleme']) ? $_POST['probleme'] : NULL;
        $resolution = !empty($_POST['resolution']) ? $_POST['resolution'] : NULL;
        $status = !empty($_POST['status']) ? $_POST['status'] : NULL;
        $password  = !empty($_POST['password ']) ? $_POST['password '] : NULL;
        $tel  = !empty($_POST['tel ']) ? $_POST['tel '] : NULL;
        $tel2  = !empty($_POST['tel2 ']) ? $_POST['tel2 '] : NULL;
        $siteweb  = !empty($_POST['siteweb ']) ? $_POST['siteweb '] : NULL;
        $email  = !empty($_POST['email ']) ? $_POST['email '] : NULL;
        $user  = !empty($_POST['user ']) ? $_POST['user'] : NULL;
        $idmateriel   = !empty($_POST['idmateriel  ']) ? $_POST['idmateriel '] : NULL;
        $login    = !empty($_POST['login   ']) ? $_POST['login'] : NULL;
        $dt = new DateTime('Europe/Paris');
        $date = $dt->format('Y-m-d H:i:s');
        $idclient    = !empty($_POST['idclient']) ? $_POST['idclient'] : NULL;
        $client = !empty($_POST['client']) ? $_POST['client'] : NULL;
        $nom   = !empty($_POST['nom']) ? $_POST['nom '] : NULL;
        $prenom   = !empty($_POST['prenom  ']) ? $_POST['prenom '] : NULL;
        $ville   = !empty($_POST['ville  ']) ? $_POST['ville '] : NULL;
        $codepostal   = !empty($_POST['codepostal  ']) ? $_POST['codepostal '] : NULL;
        $adresse   = !empty($_POST['adresse  ']) ? $_POST['adresse '] : NULL;
        $adresse2   = !empty($_POST['adresse2  ']) ? $_POST['adresse2 '] : NULL;
        $pays   = !empty($_POST['pays  ']) ? $_POST['pays'] : NULL;
        $societe   = !empty($_POST['societe  ']) ? $_POST['societe '] : NULL;
        $goClient  = !empty($_POST['goClient']) ? $_POST['goClient'] : NULL;
        $civilite  = !empty($_POST['civilite']) ? $_POST['civilite'] : NULL;
        $choixgrp   = !empty($_POST['choixgrp ']) ? $_POST['choixgrp '] : NULL;
        $detail   = !empty($_POST['detail']) ? $_POST['detail'] : NULL;
     
     
    //insère les données dans la base de données
     
     
        //si le client existe on le recherche
        if ($goClient == 1)
        {
            if ($idclient == "")
            {
                $_GET["msg"] = "Veuillez choisir un client";
            }
            else
            {
                //fait un requête pour selection l'id de l'user pour savoir si il existe ou pas
     
                $r = mysql_query("SELECT iduser FROM esf_clients WHERE idclient='$idclient';",$bdd2) or die(mysql_error());
                if (mysql_num_rows($r)==0)
                {
                    $_GET["msg"] = "Le client n'existe pas ...";
                    $idclient = 0;
                }
                else
                {
                    $user = mysql_result($r,0,"iduser");
                }
            }
        }
        //si le client n'existe pas on le créer
        if ($goClient == 0)
        {
            //prépare la requête sql
     
     
            $r = mysql_query("INSERT INTO esf_clients VALUES ('','','$societe','$civilite','$nom','$prenom','$adresse','$adresse2','$ville','$codepostal','$pays','$tel','$tel2','','','$email','$siteweb','','','','','$login','$password','','','1','$user');",$bdd2) or die(mysql_error());
            $idclient = mysql_insert_id();
     
            foreach($choixgrp as $grp)
            {
                $r = mysql_query("INSERT INTO esf_clients_grp VALUES ('$idclient','$grp');",$bdd2) or die(mysql_error());
            }
     
            exit();
        }
        $req = $bddtest->prepare("INSERT INTO ticket (probleme, date_creation, resolution, status, idmateriel, idclient) VALUES (:probleme, :date_creation, :resolution, :status, :idmateriel, :idclient)");
        $req->execute(array(
            "probleme" => $probleme,
            "date_creation" => $date,
            "resolution" => $resolution,
            "status" => $status,
            "idmateriel" => $idmateriel,
            "idclient" => $idclient,
        ));
     
     
    }
     
    else
    {
     
     
     
    //valeurs par default
        $goClient = 1;
        $idclient = !empty($_GET['idclient']) ? $_GET['idclient'] : NULL;
        $client = !empty($_POST['client']) ? $_POST['client'] : NULL;
        $nom   = !empty($_POST['nom']) ? $_POST['nom '] : NULL;
        $prenom   = !empty($_POST['prenom  ']) ? $_POST['prenom '] : NULL;
        $ville   = !empty($_POST['ville  ']) ? $_POST['ville '] : NULL;
        $codepostal   = !empty($_POST['codepostal  ']) ? $_POST['codepostal '] : NULL;
        $adresse   = !empty($_POST['adresse  ']) ? $_POST['adresse '] : NULL;
        $adresse2   = !empty($_POST['adresse2  ']) ? $_POST['adresse2 '] : NULL;
        $pays   = !empty($_POST['pays  ']) ? $_POST['pays'] : NULL;
        $societe   = !empty($_POST['societe  ']) ? $_POST['societe '] : NULL;
        $fond = "";
        $commentaire_interne = "";
        $civilite = "Mr";
     
        $detail = 0;
        $tel = "";
        $tel2 = "";
        $siteweb = "http://";
        $email = "";
        $choixgrp = array();
        $fichiers = array();
    }
    if ($goClient == 1) { $display0 = "none"; $display1 = "block"; $display2 = "none"; }
    if ($goClient == 0) { $display0 = "block"; $display1 = "none"; $display2 = "none"; }
     
    if ($detail == 1) $display2 = "block";
     
    if ($idclient != 0) $client = infosClient($idclient);
     
    ?>
     
    <!-- script pour quand on change de page par rapport au client existant ou au client non existant -->
    <script type="text/javascript">
     
        function changeClient() {
            if (document.getElementById('goClient1').checked)
            {
                document.getElementById('clientExiste').style.display = 'none';
                document.getElementById('clientExistePas').style.display = 'block';
            }
            else
            {
                document.getElementById('clientExiste').style.display = 'block';
                document.getElementById('clientExistePas').style.display = 'none';
            }
        }
     
        function changeClientDetail() {
            if (document.getElementById('detail').checked)
            {
                document.getElementById('clientDetail').style.display = 'block';
            }
            else
            {
                document.getElementById('clientDetail').style.display = 'none';
            }
        }
     
    </script>
     
    <link href="style.css" rel="stylesheet" type="text/css">
    <SCRIPT LANGUAGE="JavaScript" src="js/jquery.js"></SCRIPT>
    <SCRIPT LANGUAGE="JavaScript" src="js/script.js"></SCRIPT>
    <meta charset="UTF-8">
    <!-- formulaire pour ajout de ticket -->
    <form  method="post" action="ajoutTicket.php" >
     
     
        <table border="0" align="center" width="95%">
            <tr>
                <td width="50%" style="height: 50px;background-color: #36393D;font-size: 16px;text-align: center; color: #ffffff;font-weight: bold;"><input class="cb" type="radio" name="goClient" onclick="javascript: changeClient();" id="goClient1" value="0" <?php if ($goClient == 0) echo("checked=\"checked\""); ?> /> <label for="goClient1">Le client n'existe pas</label></td>
                <td width="50%" style="height: 50px;background-color: #C3D9FF;font-size: 16px;text-align: center; color: #000000;font-weight: bold;"><input class="cb" type="radio" name="goClient" onclick="javascript: changeClient();" id="goClient2" value="1" <?php if ($goClient == 1) echo("checked=\"checked\""); ?> /> <label for="goClient2">Le client existe déjà</label></td>
            </tr>
        </table>
     
     
     
        <div id="clientExiste" style="display: <?php echo($display1); ?>;">
            <table border="0" align="center" cellpadding="5" width="95%">
                <tr class="titre">
                    <td colspan="4">Client : </td>
                </tr>
                <tr class="fond1">
                            <tr class="fond1"><td> Client :</td><td><input type="text" id="keyword" tabindex="0" autocomplete="off" class="infos"><img src="images/loading.gif" id="loading"></td></tr>
                        <tr><td><div id="ajax_response"></div></td></tr>
            </table>
        </div>
     
        <div id="clientExistePas" style="display: <?php echo($display0); ?>;">
            <table border="0" align="center" cellpadding="5" width="95%">
                <tr class="titre">
                    <td colspan="4">Client : </td>
                </tr>
                <tr class="fond1">
                    <td>Civlité :</td>
                    <td colspan="3"><input type="radio" name="civilite" class="cb" value="Mr" <?php if ($civilite == "Mr") echo(" checked=\"checked\""); ?> /> Mr
                        <input type="radio" name="civilite" class="cb" value="Mme" <?php if ($civilite == "Mme") echo(" checked=\"checked\""); ?> /> Mme
                        <input type="radio" name="civilite" class="cb" value="Mlle" <?php if ($civilite == "Mlle") echo(" checked=\"checked\""); ?> /> Mlle</td>
                </tr>
                <tr class="fond2">
                    <td width="15%">Nom <span class="important">*</span> :</td>
                    <td width="35%"><input type="text" name="nom" size="25" value="<?php echo($nom); ?>" /></td>
                    <td width="15%">Prénom <span class="important">*</span> :</td>
                    <td width="35%"><input type="text" name="prenom" size="25" value="<?php echo($prenom); ?>" /></td>
                </tr>
                <tr class="fond1">
                    <td><u><b>ET / OU</b></u> Société <span class="important">*</span> :</td>
                    <td colspan="3"><input type="text" name="societe" size="45" value="<?php echo($societe); ?>" /></td>
                </tr>
                <tr class="fond2">
                    <td>Adresse :</td>
                    <td colspan="3"><input type="text" name="adresse" size="70" value="<?php echo($adresse); ?>" /></td>
                </tr>
                <tr class="fond1">
                    <td></td>
                    <td colspan="3"><input type="text" name="adresse2" size="70" value="<?php echo($adresse2); ?>" /></td>
                </tr>
                <tr class="fond2">
                    <td>Code postal</td>
                    <td><input type="text" name="codepostal" size="10" value="<?php echo($codepostal); ?>" /></td>
                    <td>Ville :</td>
                    <td><input type="text" name="ville" size="35" value="<?php echo($ville); ?>" /></td>
                </tr>
                <tr class="fond1">
                    <td>Pays :</td>
                    <td colspan="3"><input type="text" name="pays" size="25" value="<?php echo($pays); ?>" /></td>
                </tr>
                <tr class="fond2">
                    <td colspan="4"><input type="checkbox" class="cb" name="detail" id="detail" <?php if ($detail == 1) echo("checked=\"checked\""); ?> value="1" onclick="javascript: changeClientDetail();" /> Plus d'informations</td>
                </tr>
            </table>
        </div>
     
        <div id="clientDetail" style="display: <?php echo($display2); ?>;">
            <table border="0" align="center" cellpadding="5" width="95%">
                <tr class="titre">
                    <td colspan="4">Plus d'informations : </td>
                </tr>
                <tr class="fond1">
                    <td width="15%">Téléphone 1 :</td>
                    <td width="35%"><input type="text" name="tel" size="25" value="<?php echo($tel); ?>" /></td>
                    <td width="15%">Téléphone 2 :</td>
                    <td width="35%"><input type="text" name="tel2" size="25" value="<?php echo($tel2); ?>" /></td>
                </tr>
                <tr class="fond2">
                    <td>E-mail :</td>
                    <td><input type="text" name="email" size="30" value="<?php echo($email); ?>" /></td>
                    <td>Site Web :</td>
                    <td><input type="text" name="siteweb" size="30" value="<?php echo($siteweb); ?>" /></td>
                </tr>
                <tr class="fond1">
                    <td>Groupe :</td>
                    <td colspan="3"><select name="choixgrp[]" multiple="multiple" size="5" style="width: 350px;">
                            <?php
     
                            $r = mysql_query("select * from esf_clients_groupes order by titre;",$bdd2);
                            while($ligne = mysql_fetch_array($r))
                            {
                                $idgrp = $ligne["idgrp"];
                                $titregrp = $ligne["titre"];
     
                                echo("<option value=\"$idgrp\"");
                                if (in_array($idgrp,$choixgrp)) echo(" selected=\"selected\"");
                                echo(">$titregrp</option>");
                            }
     
                            ?>
                        </select></td>
                </tr>
            </table>
        </div>
        <table border="0" align="center" cellpadding="5" width="95%">
            <tr class="titre">
                <td colspan="4">Ticket : </td>
            </tr>
            <!-- champ de texte probleme -->
            <tr class="fond2">
                <td>Problème :</td>
                <td><textarea name="probleme" cols="45" rows="5"></textarea></td>
            </tr>
            <!-- champ de texte resolution -->
            <tr class="fond1">
                <td>Resolution :</td>
                <td><textarea name="resolution" cols="45" rows="5"></textarea></td>
            </tr>
            <!-- liste déroulante pour les pc existants -->
            <tr class="fond2"> <td>ordinateurs :
                </td><td><a href="">Créer un nouvel ordinateur</a><br><br><select name="idmateriel">
                        <?php
                        $bdd = new PDO('mysql:host=localhost;dbname=projet-facturier', "root", 'root');
                        $reponse = $bdd->query("SELECT * FROM materiel where idclient = '.$idclient.'");
                        while ($donnees = $reponse->fetch()) {
                            ?>
                            <option value="<?php echo $donnees['id'];?>"><?php echo $donnees['nom'], $donnees['processeur'];?></option>
                        <?php  } ?>
                    </select></td></tr>
     
     
     
     
            <!-- liste déroulante -->
            <tr class="fond1">
                <td>status : </td>
                <td>
                    <select name="status" size="1">
                        <option>--Status--</option>
                        <option>en cours</option>
                        <option>en attente</option>
                        <option>clos</option>
                    </SELECT></td>
            </tr>
     
     
                <!-- bouton d'envoi -->
     
     
     
        </table>
        <div align="center" class="test"><input type="submit" name="submit" value="Créer" class="submit" /></div>
    </form>

  2. #2
    Membre émérite Avatar de Willy_k
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2011
    Messages
    541
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Côte d'Ivoire

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2011
    Messages : 541
    Par défaut
    Bonjour,
    ce que vous allez faire c'est avoir un peu de cohérence dans le code en convertissant toutes les parties mysql_xxxx en PDO, ça sera déjà un pas.. On ne mixe pas comme ça les extensions.
    Et quel est besoin qui vous a amené à travailler avec 2 bases de données ?

  3. #3
    Membre averti
    Femme Profil pro
    Développeur Web
    Inscrit en
    Juin 2017
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 31
    Localisation : France, Mayenne (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Juin 2017
    Messages : 17
    Par défaut
    Bonjour oui je viens juste de le faire j'ai tout mis en pdo. Le besoin c'est que la personne pour qui je travail veux 2 bases de donnée pour sa parce que les tables vont êtres grosse et il ne veut pas grossir sa base de donnée de base.

  4. #4
    Membre chevronné
    Homme Profil pro
    Autres
    Inscrit en
    Mai 2017
    Messages
    279
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Autres

    Informations forums :
    Inscription : Mai 2017
    Messages : 279
    Par défaut
    L'extension mysql est déprécié dépuis le version 5.6. Soit tu utilises mysqli soit PDO et mélanger des extensions comme tu l'as fait avec mysl et PDO n'est pas professionnel .
    Quelle est l'intérêt de travailler sur 02 Bases de données pour ce projet? Ne serait-il pas préférable de régler le problème à l'aide de jointures entre différentes table?

  5. #5
    Membre averti
    Femme Profil pro
    Développeur Web
    Inscrit en
    Juin 2017
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 31
    Localisation : France, Mayenne (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Juin 2017
    Messages : 17
    Par défaut
    ah oui j'ai pas préciser la base de donnée de base est en mysql 5.5 et il ne veut pas l'upgrader.

  6. #6
    Membre émérite Avatar de Willy_k
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2011
    Messages
    541
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Côte d'Ivoire

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2011
    Messages : 541
    Par défaut
    Postez votre nouveau code..
    Mais la question reste posée, pourquoi 2 BDD ?
    Cette version de MYSQL ne devrait pas poser problème.

  7. #7
    Membre chevronné
    Homme Profil pro
    Autres
    Inscrit en
    Mai 2017
    Messages
    279
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Autres

    Informations forums :
    Inscription : Mai 2017
    Messages : 279
    Par défaut
    Tu pourras faire le lien à l'aide des clefs: tu mets en relation les tables de la base de données 1 avec celles de la base de données 2.
    Supposons par exemple que j'ai une base de données client qui porte le informations des clients et une autre site qui porte celle des sites.
    Dans ma base de données sites, je mets un champ client_id, clé étrangère en référence de l'id du client dans la base de données client. Lorsque je veux enregistrer le site d'un client, A partir de la basse de données de client, je récupère la liste des clients dans une liste déroulante. Quand l'utilisateur sélectionne un client, J'utilise son id pour créer le site dans la base de données site.
    Pour le faire, je dois gérer deux connexions à deux bases de données: C'est le cas avec certains projets.

  8. #8
    Membre averti
    Femme Profil pro
    Développeur Web
    Inscrit en
    Juin 2017
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 31
    Localisation : France, Mayenne (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Juin 2017
    Messages : 17
    Par défaut
    @Willy_k voici mon nouveau code avec le PDO
    code de mon php + 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
    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
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
     
    <?php
     
    include("../inc/fonctions.php");
    include('index.php');
     
    $bdd = new PDO("mysql:host=localhost;dbname=projet-facturier", "root","root");
    $bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $bdd2 = new PDO("mysql:host=localhost;dbname=facturier", "root","root");
    $bdd2->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    if (isset($_POST["submit"])) {
     
    //récupère les données qui ont été saisie dans le formulaire
        $probleme = !empty($_POST['probleme']) ? $_POST['probleme'] : NULL;
        $resolution = !empty($_POST['resolution']) ? $_POST['resolution'] : NULL;
        $status = !empty($_POST['status']) ? $_POST['status'] : NULL;
        $password  = !empty($_POST['password ']) ? $_POST['password '] : NULL;
        $tel  = !empty($_POST['tel ']) ? $_POST['tel '] : NULL;
        $tel2  = !empty($_POST['tel2 ']) ? $_POST['tel2 '] : NULL;
        $siteweb  = !empty($_POST['siteweb ']) ? $_POST['siteweb '] : NULL;
        $email  = !empty($_POST['email ']) ? $_POST['email '] : NULL;
        $user  = !empty($_POST['user ']) ? $_POST['user'] : NULL;
        $idmateriel   = !empty($_POST['idmateriel  ']) ? $_POST['idmateriel '] : NULL;
        $login    = !empty($_POST['login   ']) ? $_POST['login'] : NULL;
        $dt = new DateTime('Europe/Paris');
        $date = $dt->format('Y-m-d H:i:s');
        $idclient    = !empty($_POST['idclient']) ? $_POST['idclient'] : NULL;
        $client = !empty($_POST['client']) ? $_POST['client'] : NULL;
        $nom   = !empty($_POST['nom']) ? $_POST['nom '] : NULL;
        $prenom   = !empty($_POST['prenom  ']) ? $_POST['prenom '] : NULL;
        $ville   = !empty($_POST['ville  ']) ? $_POST['ville '] : NULL;
        $codepostal   = !empty($_POST['codepostal  ']) ? $_POST['codepostal '] : NULL;
        $adresse   = !empty($_POST['adresse  ']) ? $_POST['adresse '] : NULL;
        $adresse2   = !empty($_POST['adresse2  ']) ? $_POST['adresse2 '] : NULL;
        $pays   = !empty($_POST['pays  ']) ? $_POST['pays'] : NULL;
        $societe   = !empty($_POST['societe  ']) ? $_POST['societe '] : NULL;
        $goClient  = !empty($_POST['goClient']) ? $_POST['goClient'] : NULL;
        $civilite  = !empty($_POST['civilite']) ? $_POST['civilite'] : NULL;
        $choixgrp   = !empty($_POST['choixgrp ']) ? $_POST['choixgrp '] : NULL;
        $detail   = !empty($_POST['detail']) ? $_POST['detail'] : NULL;
     
     
    //insère les données dans la base de données
     
     
        //si le client existe on le recherche
        if ($goClient == 1)
        {
            if ($idclient == "")
            {
                $_GET["msg"] = "Veuillez choisir un client";
            }
            else
            {
                //fait un requête pour selection l'id de l'user pour savoir si il existe ou pas
     
                $r = $bdd2->query("SELECT iduser FROM esf_clients WHERE idclient='$idclient';");
                if (mysql_num_rows($r)==0)
                {
                    $_GET["msg"] = "Le client n'existe pas ...";
                    $idclient = 0;
                }
                else
                {
                    $user = mysql_result($r,0,"iduser");
                }
            }
        }
        //si le client n'existe pas on le créer
        if ($goClient == 0)
        {
            //prépare la requête sql
     
     
            $r = $bdd2->query("INSERT INTO esf_clients VALUES ('','','$societe','$civilite','$nom','$prenom','$adresse','$adresse2','$ville','$codepostal','$pays','$tel','$tel2','','','$email','$siteweb','','','','','$login','$password','','','1','$user');");
            $idclient = mysql_insert_id();
     
            foreach($choixgrp as $grp)
            {
                $r = $bdd2->query("INSERT INTO esf_clients_grp VALUES ('$idclient','$grp');",$bdd2);
            }
     
            exit();
        }
        $req = $bddtest->prepare("INSERT INTO ticket (probleme, date_creation, resolution, status, idmateriel, idclient) VALUES (:probleme, :date_creation, :resolution, :status, :idmateriel, :idclient)");
        $req->execute(array(
            "probleme" => $probleme,
            "date_creation" => $date,
            "resolution" => $resolution,
            "status" => $status,
            "idmateriel" => $idmateriel,
            "idclient" => $idclient,
        ));
     
     
    }
     
    else
    {
     
     
     
    //valeurs par default
        $goClient = 1;
        $idclient = !empty($_GET['idclient']) ? $_GET['idclient'] : NULL;
        $client = !empty($_POST['client']) ? $_POST['client'] : NULL;
        $nom   = !empty($_POST['nom']) ? $_POST['nom '] : NULL;
        $prenom   = !empty($_POST['prenom  ']) ? $_POST['prenom '] : NULL;
        $ville   = !empty($_POST['ville  ']) ? $_POST['ville '] : NULL;
        $codepostal   = !empty($_POST['codepostal  ']) ? $_POST['codepostal '] : NULL;
        $adresse   = !empty($_POST['adresse  ']) ? $_POST['adresse '] : NULL;
        $adresse2   = !empty($_POST['adresse2  ']) ? $_POST['adresse2 '] : NULL;
        $pays   = !empty($_POST['pays  ']) ? $_POST['pays'] : NULL;
        $societe   = !empty($_POST['societe  ']) ? $_POST['societe '] : NULL;
        $fond = "";
        $commentaire_interne = "";
        $civilite = "Mr";
     
        $detail = 0;
        $tel = "";
        $tel2 = "";
        $siteweb = "http://";
        $email = "";
        $choixgrp = array();
        $fichiers = array();
    }
    if ($goClient == 1) { $display0 = "none"; $display1 = "block"; $display2 = "none"; }
    if ($goClient == 0) { $display0 = "block"; $display1 = "none"; $display2 = "none"; }
     
    if ($detail == 1) $display2 = "block";
     
    if ($idclient != 0) $client = infosClient($idclient);
     
    ?>
     
    <!-- script pour quand on change de page par rapport au client existant ou au client non existant -->
    <script type="text/javascript">
     
        function changeClient() {
            if (document.getElementById('goClient1').checked)
            {
                document.getElementById('clientExiste').style.display = 'none';
                document.getElementById('clientExistePas').style.display = 'block';
            }
            else
            {
                document.getElementById('clientExiste').style.display = 'block';
                document.getElementById('clientExistePas').style.display = 'none';
            }
        }
     
        function changeClientDetail() {
            if (document.getElementById('detail').checked)
            {
                document.getElementById('clientDetail').style.display = 'block';
            }
            else
            {
                document.getElementById('clientDetail').style.display = 'none';
            }
        }
     
    </script>
     
    <link href="style.css" rel="stylesheet" type="text/css">
    <SCRIPT LANGUAGE="JavaScript" src="js/jquery.js"></SCRIPT>
    <SCRIPT LANGUAGE="JavaScript" src="js/script.js"></SCRIPT>
    <meta charset="UTF-8">
    <!-- formulaire pour ajout de ticket -->
    <form  method="post" action="ajoutTicket.php" >
     
     
        <table border="0" align="center" width="95%">
            <tr>
                <td width="50%" style="height: 50px;background-color: #36393D;font-size: 16px;text-align: center; color: #ffffff;font-weight: bold;"><input class="cb" type="radio" name="goClient" onclick="javascript: changeClient();" id="goClient1" value="0" <?php if ($goClient == 0) echo("checked=\"checked\""); ?> /> <label for="goClient1">Le client n'existe pas</label></td>
                <td width="50%" style="height: 50px;background-color: #C3D9FF;font-size: 16px;text-align: center; color: #000000;font-weight: bold;"><input class="cb" type="radio" name="goClient" onclick="javascript: changeClient();" id="goClient2" value="1" <?php if ($goClient == 1) echo("checked=\"checked\""); ?> /> <label for="goClient2">Le client existe déjà</label></td>
            </tr>
        </table>
     
     
     
        <div id="clientExiste" style="display: <?php echo($display1); ?>;">
            <table border="0" align="center" cellpadding="5" width="95%">
                <tr class="titre">
                    <td colspan="4">Client : </td>
                </tr>
                <tr class="fond1">
                            <tr class="fond1"><td> Client :</td><td><input type="text" id="keyword" tabindex="0" autocomplete="off" class="infos"><img src="images/loading.gif" id="loading"></td></tr>
                        <tr><td><div id="ajax_response"></div></td></tr>
            </table>
        </div>
     
        <div id="clientExistePas" style="display: <?php echo($display0); ?>;">
            <table border="0" align="center" cellpadding="5" width="95%">
                <tr class="titre">
                    <td colspan="4">Client : </td>
                </tr>
                <tr class="fond1">
                    <td>Civlité :</td>
                    <td colspan="3"><input type="radio" name="civilite" class="cb" value="Mr" <?php if ($civilite == "Mr") echo(" checked=\"checked\""); ?> /> Mr
                        <input type="radio" name="civilite" class="cb" value="Mme" <?php if ($civilite == "Mme") echo(" checked=\"checked\""); ?> /> Mme
                        <input type="radio" name="civilite" class="cb" value="Mlle" <?php if ($civilite == "Mlle") echo(" checked=\"checked\""); ?> /> Mlle</td>
                </tr>
                <tr class="fond2">
                    <td width="15%">Nom <span class="important">*</span> :</td>
                    <td width="35%"><input type="text" name="nom" size="25" value="<?php echo($nom); ?>" /></td>
                    <td width="15%">Prénom <span class="important">*</span> :</td>
                    <td width="35%"><input type="text" name="prenom" size="25" value="<?php echo($prenom); ?>" /></td>
                </tr>
                <tr class="fond1">
                    <td><u><b>ET / OU</b></u> Société <span class="important">*</span> :</td>
                    <td colspan="3"><input type="text" name="societe" size="45" value="<?php echo($societe); ?>" /></td>
                </tr>
                <tr class="fond2">
                    <td>Adresse :</td>
                    <td colspan="3"><input type="text" name="adresse" size="70" value="<?php echo($adresse); ?>" /></td>
                </tr>
                <tr class="fond1">
                    <td></td>
                    <td colspan="3"><input type="text" name="adresse2" size="70" value="<?php echo($adresse2); ?>" /></td>
                </tr>
                <tr class="fond2">
                    <td>Code postal</td>
                    <td><input type="text" name="codepostal" size="10" value="<?php echo($codepostal); ?>" /></td>
                    <td>Ville :</td>
                    <td><input type="text" name="ville" size="35" value="<?php echo($ville); ?>" /></td>
                </tr>
                <tr class="fond1">
                    <td>Pays :</td>
                    <td colspan="3"><input type="text" name="pays" size="25" value="<?php echo($pays); ?>" /></td>
                </tr>
                <tr class="fond2">
                    <td colspan="4"><input type="checkbox" class="cb" name="detail" id="detail" <?php if ($detail == 1) echo("checked=\"checked\""); ?> value="1" onclick="javascript: changeClientDetail();" /> Plus d'informations</td>
                </tr>
            </table>
        </div>
     
        <div id="clientDetail" style="display: <?php echo($display2); ?>;">
            <table border="0" align="center" cellpadding="5" width="95%">
                <tr class="titre">
                    <td colspan="4">Plus d'informations : </td>
                </tr>
                <tr class="fond1">
                    <td width="15%">Téléphone 1 :</td>
                    <td width="35%"><input type="text" name="tel" size="25" value="<?php echo($tel); ?>" /></td>
                    <td width="15%">Téléphone 2 :</td>
                    <td width="35%"><input type="text" name="tel2" size="25" value="<?php echo($tel2); ?>" /></td>
                </tr>
                <tr class="fond2">
                    <td>E-mail :</td>
                    <td><input type="text" name="email" size="30" value="<?php echo($email); ?>" /></td>
                    <td>Site Web :</td>
                    <td><input type="text" name="siteweb" size="30" value="<?php echo($siteweb); ?>" /></td>
                </tr>
                <tr class="fond1">
                    <td>Groupe :</td>
                    <td colspan="3"><select name="choixgrp[]" multiple="multiple" size="5" style="width: 350px;">
                            <?php
     
                            $r = $bdd2->query("select * from esf_clients_groupes order by titre;");
                            while($ligne = $r->fetch())
                            {
                                $idgrp = $ligne["idgrp"];
                                $titregrp = $ligne["titre"];
     
                                echo("<option value=\"$idgrp\"");
                                if (in_array($idgrp,$choixgrp)) echo(" selected=\"selected\"");
                                echo(">$titregrp</option>");
                            }
     
                            ?>
                        </select></td>
                </tr>
            </table>
        </div>
        <table border="0" align="center" cellpadding="5" width="95%">
            <tr class="titre">
                <td colspan="4">Ticket : </td>
            </tr>
            <!-- champ de texte probleme -->
            <tr class="fond2">
                <td>Problème :</td>
                <td><textarea name="probleme" cols="45" rows="5"></textarea></td>
            </tr>
            <!-- champ de texte resolution -->
            <tr class="fond1">
                <td>Resolution :</td>
                <td><textarea name="resolution" cols="45" rows="5"></textarea></td>
            </tr>
            <!-- liste déroulante pour les pc existants -->
            <tr class="fond2"> <td>ordinateurs :
                </td><td><a href="">Créer un nouvel ordinateur</a><br><br><select name="idmateriel">
                        <?php
     
                        $reponse = $bdd->query("SELECT * FROM materiel where idclient = '.$idclient.'");
                        while ($donnees = $reponse->fetch()) {
                            ?>
                            <option value="<?php echo $donnees['id'];?>"><?php echo $donnees['nom'], $donnees['processeur'];?></option>
                        <?php  } ?>
                    </select></td></tr>
     
     
     
     
            <!-- liste déroulante -->
            <tr class="fond1">
                <td>status : </td>
                <td>
                    <select name="status" size="1">
                        <option>--Status--</option>
                        <option>en cours</option>
                        <option>en attente</option>
                        <option>clos</option>
                    </SELECT></td>
            </tr>
     
     
                <!-- bouton d'envoi -->
     
     
     
        </table>
        <div align="center" class="test"><input type="submit" name="submit" value="Créer" class="submit" /></div>
    </form>
    code pour ma recherche dynamique :
    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
     
    <?php
    include("config.php");
    $keyword = $_POST['data'];
    $result =$bdd2->query("select * from ".$db_table." where ".$db_column." like '".$keyword."%' or ".$db_column2." like '".$keyword."%' or ".$db_column3." like '".$keyword."%'limit 0,20");
    //$sql = "select name from ".$db_table."";
     
    if($result->rowCount())
    {
        echo '<ul class="list">';
        while($row = $result->fetch())
        {
            $str = strtolower($row['nom']);
            $start = strpos($str,$keyword);
            $end   = similar_text($str,$keyword);
            $last = substr($str,$end,strlen($str));
            $first = substr($str,$start,$end);
     
            $str2 = strtolower($row['prenom']);
            $start2 = strpos($str2,$keyword);
            $end2   = similar_text($str2,$keyword);
            $last2 = substr($str2,$end2,strlen($str2));
            $first2 = substr($str2,$start2,$end2);
     
            $str3 = strtolower($row['email']);
            $start3 = strpos($str3,1);
            $end3   = similar_text($str3,$keyword);
            $last3 = substr($str3,$end3,strlen($str3));
            $first3 = substr($str3,$start3,$end3);
     
            $str4 = strtolower($row['adresse']);
            $start4 = strpos($str4,$keyword);
            $end4   = similar_text($str4,$keyword);
            $last4= substr($str4,$end4,strlen($str4));
            $first4 = substr($str4,$start4,$end4);
     
            $str5 = strtolower($row['ville']);
            $start5 = strpos($str5,$keyword);
            $end5   = similar_text($str5,$keyword);
            $last5 = substr($str5,$end5,strlen($str5));
            $first5 = substr($str5,$start5,$end5);
     
            $idclient = strtolower($row['idclient']);
            $start6 = strpos($idclient,$keyword);
            $end6   = similar_text($idclient,$keyword);
            $last6 = substr($idclient,$end6,strlen($idclient));
            $first6 = substr($idclient,$start6,$end6);
     
            $final = '<span class="bold">'.$first.'</span>'.$last;
            $final2 = '<span class="bold">'.$first2.'</span>'.$last2;
            $final3 = '<span class="mail">'.$first3.'</span><span class="mail">'.$last3.'</span>';
            $final4 = '<span class="adresse">'.$first4.'</span><span class="adresse">'.$last4.',</span>';
            $final5 = '<span class="adresse">'.$first5.'</span><span class="adresse">'.$last5.'</span>';
            $final6 = '<span class="adresse">'.$first6.'</span><span class="adresse">'.$last6.'</span>';
            echo '<li><a href=\'javascript:void(0);\'>'.$final.' '.$final2.' <br>'.$final3.' <br>'.$final4.' '.$final5.'<br>'. $final6 .'</a></li>';
        }
        echo "</ul>";
    }
    else
        echo "client non trouvé";
    ?>

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

Discussions similaires

  1. [TIBSQL] Problème de récupération d'un champs
    Par TitiFr dans le forum Bases de données
    Réponses: 6
    Dernier message: 07/08/2005, 13h33
  2. [hibernate]Problème de récupération d'objet...
    Par roxx62 dans le forum Hibernate
    Réponses: 1
    Dernier message: 07/07/2005, 11h36
  3. Réponses: 8
    Dernier message: 12/05/2005, 08h16
  4. Nouveau problème de récupération de valeurs.
    Par pmboutteau dans le forum ASP
    Réponses: 4
    Dernier message: 09/03/2005, 10h48
  5. Problème de récupération de texte de formulaire
    Par bigourson dans le forum Langage
    Réponses: 4
    Dernier message: 15/09/2004, 16h27

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