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 :

Problème avec ma Barre de Recherche PHP [MySQL]


Sujet :

PHP & Base de données

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2012
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

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

    Informations forums :
    Inscription : Mai 2012
    Messages : 14
    Points : 9
    Points
    9
    Par défaut Problème avec ma Barre de Recherche PHP
    Bonsoir la famille! au fait je suis en train de develloper un petit site d'annonces, pour le moment tout va bien mais sur ma page d'affichage d'annonces j'ai un petit souci à propos de ma barre de recherche ...pour le moment j'ai 3 formulaires 1 de type text et 2 listes deroulantes..Si je lance une recherche avec le type text je reçoit des resultat mais par contre les autres (liste deroulantes ) ça ne donne rien je ne sais pas si c'est un probleme lier au code ou bienà ma base de donnée.

    Voila je suis venu pour avoir de l'aide mes chers amis

    Voici le code de la page:
    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
     
    <?php
    session_start();
    require_once 'class.user.php';
    $user_home = new USER();
     
    if(!$user_home->is_logged_in())
    {
    	$user_home->redirect('index.php');
    }
     
    $stmt = $user_home->runQuery("SELECT * FROM tbl_users WHERE userID=:uid");
    $stmt->execute(array(":uid"=>$_SESSION['userSession']));
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    $id_user=$row['userID'];
     
    // DEBU PAGINATION
    $bdd = new PDO("mysql:host=127.0.0.1;dbname=dbtest;charset=utf8", "root", "");
    $annoncesParPage = 3;
    $annoncesTotalesReq = $bdd->query('SELECT annonce_id FROM annonce');
    $annoncesTotales = $annoncesTotalesReq->rowCount();
    $pagesTotales = ceil($annoncesTotales/$annoncesParPage);
    if(isset($_GET['page']) AND !empty($_GET['page']) AND $_GET['page'] > 0 AND $_GET['page'] <= $pagesTotales) {
       $_GET['page'] = intval($_GET['page']);
       $pageCourante = $_GET['page'];
    } else {
       $pageCourante = 1;
    }
    $depart = ($pageCourante-1)*$annoncesParPage;
    // FIN PAGINATION
     
     
    //DEBUT BARRE DE RECHERCHE
    $bdd = new PDO('mysql:host=127.0.0.1;dbname=dbtest;charset=utf8', 'root', '');
    		 $stmt = $bdd->query("SELECT tbl_users.userID, tbl_users.userType, annonce.*, categorie.id_categorie, typecat.* FROM annonce INNER JOIN tbl_users ON annonce.user_id = tbl_users.userID INNER JOIN categorie ON categorie.id_categorie = annonce.categorie_id INNER JOIN typecat ON typecat.categorie_id = categorie.id_categorie ORDER BY annonce.date_annonce DESC LIMIT ".$depart.','.$annoncesParPage);
     
    		 if(isset($_POST['titre']) && $_POST['titre'] != ""){
    			 $titre = htmlspecialchars($_POST['titre']);
    			 $stmt = $bdd->query('SELECT tbl_users.userID, tbl_users.userType, annonce.*, categorie.*, typecat.* FROM annonce INNER JOIN tbl_users ON annonce.user_id = tbl_users.userID INNER JOIN categorie ON categorie.id_categorie = annonce.categorie_id INNER JOIN typecat ON typecat.categorie_id = categorie.id_categorie  WHERE CONCAT(titre_annonce, commentaire) LIKE "%'.$titre.'%" ORDER BY annonce.date_annonce DESC LIMIT '.$depart.','.$annoncesParPage);  
     
    		 }
    		 if(isset($_POST['cat'])){
     
    				 $stmt = $bdd->query('SELECT tbl_users.userID, tbl_users.userType, annonce.*, categorie.*, typecat.* FROM annonce INNER JOIN tbl_users ON annonce.user_id = tbl_users.userID INNER JOIN categorie ON categorie.id_categorie = annonce.categorie_id INNER JOIN typecat ON typecat.categorie_id = categorie.id_categorie  WHERE categorie.libele_cat='.$_POST['cat'].' ORDER BY annonce.date_annonce DESC LIMIT '.$depart.','.$annoncesParPage); 
    			 }	 
     
    			 if(isset($_POST['ville_ad'])){
     
    				 $stmt = $bdd->query('SELECT tbl_users.userID, tbl_users.userType, annonce.*, categorie.*, typecat.* FROM annonce INNER JOIN tbl_users ON annonce.user_id = tbl_users.userID INNER JOIN categorie ON categorie.id_categorie = annonce.categorie_id INNER JOIN typecat ON typecat.categorie_id = categorie.id_categorie  WHERE annonce.ville_annonce='.$_POST['ville_ad'].' ORDER BY annonce.date_annonce DESC LIMIT '.$depart.','.$annoncesParPage); 
    			 }	 
     
    //FIN BARRE DE RECHERHCE
    ?>
    <!DOCTYPE html>
    <html class="no-js">
     
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <title><?php echo $row['userEmail']; ?></title>
            <!-- Bootstrap -->
    		<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css">
            <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
            <link href="bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
            <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
            <link href="assets/styles.css" rel="stylesheet" media="screen">
    		<link rel="stylesheet" type="text/css" href="css/DT_bootstrap.css">
            <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
            <!--[if lt IE 9]>
                <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
            <![endif]-->
        <script src="js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>
        <script type="text/javascript" src="javascript/script.js"></script>
     
    	<script src="js/jquery.js" type="text/javascript"></script>
        <script src="js/bootstrap.js" type="text/javascript"></script>
        <script type="text/javascript" charset="utf-8" language="javascript" src="js/jquery.dataTables.js"></script>
        <script type="text/javascript" charset="utf-8" language="javascript" src="js/DT_bootstrap.js"></script>
        </head>
     
        <body>
            <?php include("topbar.php"); ?>
    		<div class="clearfix"></div>
     
     
    <div class="container-fluid" style="margin-top:80px;">
    	<div class="row-fluid">
        <div class="span12">
        <div class="container">
     
            <h4>
            <a href="index.php"><i class="fa fa-home" aria-hidden="true"></i> Accueil</a> &nbsp; 
            <a href="account.php"><i class="fa fa-user" aria-hidden="true"></i> Profile</a> &nbsp; 
    		<a href="mes-annonces.php"><i class="fa fa-bullhorn" aria-hidden="true"></i> Mes annonces</a></h4>
           	<hr />
     
            <div class="search" style="text-align: center;">
     
    		<?php  
    		 ?>
     
                <form method="POST">
                    <input type="text" name="titre" placeholder="Que recherchez-vous?" style="height: 40px; margin-top: 10px;">
     
                    <select style="height: 40px;" name="cat">
                        <option  value="toutes-categories"  disabled="disabled" selected="selected">Toutes les catégories</option>
                        <option value="informatique-et-multimedia" style="" >Informatique et Multimedia</option>
                        <option value="vehicule" style="" >Véhicules</option>
                        <option  value="immobilier" style="" >Immobilier</option>
                        <option  value="maison-et-jardin" style="" >Pour la maison et Jardin</option>
                        <option  value="habillement-et-bien-etre" style="" >Habillement et Bien Etre</option>
                        <option  value="loisirs-et-divertissement" style="" >Loisirs et Divertissement</option>
                        <option  value="emploi-et-service" style="" >Emploi et Services</option>
                        <option  value="entreprise" style="" >Entreprises</option>
                        <option  value="autres" style="" >Autres</option>
                    </select>
                    <select style="height: 40px;" name="ville_ad">
                        <option  disabled="disabled" value="" selected="selected">Toutes les villes</option>
                        <option  value="Chaouia-Ouardigha">Chaouia-Ouardigha</option>
                        <option  value="Doukkala-Abda">Doukkala-Abda</option>
                        <option  value="Fes-Boulemane">Fes Boulemane</option>
                        <option  value="Gharb-Chrarda">Gharb-Chrarda</option>
                        <option  value="Casablanca">Casablanca</option>
                        <option  value="Guelmim-Es-Semara">Guelmim-Es Semara</option>
                        <option  value="Laayoune-Boujdour">Laayoune-Boujdour</option>
                        <option  value="Marrakech">Marrakech</option>
                        <option  value="Meknes">Meknès</option>
                        <option  value="Loriental">L'oriental</option>
                        <option  value="Oued-ed-Dahab-Lagouira">Oued ed Dahab-Lagouira</option>
                        <option  value="Rabat">Rabat</option>
                        <option  value="Sale">Salé</option>
                        <option  value="Souss-Massa-Draa">Souss-Massa-Draa</option>
                        <option  value="Tadla-Azilal">Tadla-Azilal</option>
                        <option  value="Tanger-Tetouan">Tanger-Tetouan</option>
                        <option  value="Taza-Al-Taounate">Taza-Al-Taounate</option>
                        <option  value="Zaer-Zemmour">Zaer-Zemmour</option>
                    </select>
     
                    <button class="btn btn-default" type="submit" style="height: 40px;"><i class="glyphicon glyphicon-search"></i></button>
     
                </form>
            </div>
     
    		<!-- DEBUT AFFICHAGE RECHERCHE-->
           <?php
    	    if($stmt->rowCount() > 0) {
    		 while($row = $stmt->fetch()){
    			 $id_date=$row['date_annonce'];
    	   ?>
    	   <table class="table table-striped table-bordered" id="example">
             <tr>
               <td style="text-align:center; height:150px; width:150px;"><?php if($row['photo_annonce'] != ""): ?>
                  <a href="viewad.php?ad=<?php echo $row['annonce_id']; ?>"><img src="images/annonces/<?php echo $row['photo_annonce']; ?>" width="100px" height="100px"><br><span>1 Photo</span></a>
                    <?php else: ?>
                     <a href="viewad.php?ad=<?php echo $row['annonce_id']; ?>"><img src="images/upimag.png" width="100px" height="100px"><br><span>0 Photo</span></a>
                    <?php endif; ?>
               </td>
               <td style="padding-left:10px;">
                 <a href="viewad.php?ad=<?php echo $row['annonce_id']; ?>"><?php echo $row ['titre_annonce']; ?></a> 
                 <table style="margin-top:30px;">
                   <td style=" width:100px;"><?php echo $row ['prix_annonce']; ?><BR><?php echo $row ['ville_annonce']; ?></td>
                   <td style="padding-left:30px;width:500px;"><?php echo $row ['commentaire']; ?><br><?php echo $row ['type_annonce']; ?>&nbsp;publiée dans annonce:&nbsp; <?php echo $row ['libele_typecat']; ?>&nbsp;le&nbsp;<?php echo $id_date; ?></td>
                   <td style="padding-left:	20px; padding-bottom:50px;width:100px;"><?php echo $row ['userType']; ?></td>
                 </table>
               </td>
             </tr>
              <hr> 
           </table>
    		<?php } }
    		else{?> Aucun résultat trouvé...
    		<!-- FIN AFFICHAGE RECHERCHE-->
     
    		<!-- DEBUT AFFICHAGE PAGINATION-->
    	    <?php }?>
    	   <p style="text-align:center;">
    	     <?php
          for($i=1;$i<=$pagesTotales;$i++) {
             if($i == $pageCourante) {
                echo $i.' ';
             } else {?>
                <?php echo '<a href="TESTMYADS.php?page='.$i.'">'.$i.'</a> ';?>
           <?php  }
          }
          ?>
            </p>
    		<!-- FIN AFFICHAGE RECHERCHE-->
        </div>
    	</div>
        </div>
        </div>
     
    </div >
     
     
     
            <!--/.fluid-container-->
            <script src="bootstrap/js/jquery-1.9.1.min.js"></script>
            <script src="bootstrap/js/bootstrap.min.js"></script>
            <script src="assets/scripts.js"></script>
            <!--HERE IS THE FOOTER-->
       <?php include("footer.php"); ?>
        </body>
     
    </html>

    Voici une photo de mes 3 formulaires
    Nom : barre recherche.png
Affichages : 332
Taille : 4,3 Ko

    Merci de votre compréhension

  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
    On ne met pas une valeur venant de POST directement dans une requête.
    Il faut passer par une requête préparée et passer la valeur dans l’exécution :

    Également question pratique, ne repète pas la requête pour chaque cas.

    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
     
    $select = 'SELECT tbl_users.userID, tbl_users.userType, annonce.*, categorie.*, typecat.* 
                                               FROM annonce
                                               INNER JOIN tbl_users ON annonce.user_id = tbl_users.userID
                                               INNER JOIN categorie ON categorie.id_categorie = annonce.categorie_id
                                               INNER JOIN typecat ON typecat.categorie_id = categorie.id_categorie ';
     
    $order_limit = ' ORDER BY annonce.date_annonce DESC LIMIT '.$depart.','.$annoncesParPage;
     
    if(isset($_POST['titre'])){
    	$stmt = $bdd->prepare($select . ' WHERE CONCAT(titre_annonce, commentaire) LIKE ? ' . $order_limit);
            $stmt->execute(array('%'.$_POST['titre'].'%'));
    }
    elseif(isset($_POST['cat'])){
            $stmt = $bdd->prepare($select . ' WHERE categorie.libele_cat = ? ' . $order_limit);
            $stmt->execute(array($_POST['cat']));
    }
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2012
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

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

    Informations forums :
    Inscription : Mai 2012
    Messages : 14
    Points : 9
    Points
    9
    Par défaut
    Salut merci pour votre réponse...au fait avec votre modification ça me donne les resultats du premier formulaire $_POST['titre'] par contre $_POST['cat'] ça m'affiche toutes les resultats...

    Avez vous une autre suggestion SVP?

  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
    Tes cas sont mal définis : si je renseigne le champs input ET une liste, ou les deux listes en même temps ... quel condition IF s'applique ?
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2012
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

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

    Informations forums :
    Inscription : Mai 2012
    Messages : 14
    Points : 9
    Points
    9
    Par défaut
    If s'applique au 3 conditions genre ce site https://www.leboncoin.fr/annonces/offres/ile_de_france/

  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
    Tu me passes une commande pour ton code c'est ça ?

    Bref, il faut construire ta requête dynamiquement :

    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
    $select = 'SELECT tbl_users.userID, tbl_users.userType, annonce.*, categorie.*, typecat.* 
                                               FROM annonce
                                               INNER JOIN tbl_users ON annonce.user_id = tbl_users.userID
                                               INNER JOIN categorie ON categorie.id_categorie = annonce.categorie_id
                                               INNER JOIN typecat ON typecat.categorie_id = categorie.id_categorie ';
     
    $where = array();
    $param = array();
     
    if(isset($_POST['titre'])){
            $where[] = 'CONCAT(titre_annonce, commentaire) LIKE :titre';
            $param[':titre'] = '%'.$_POST['titre'].'%';
    }
    if (isset($_POST['cat'])){
            $where[] = 'categorie.libele_cat = :cat';
            $param[':cat'] = $_POST['cat'];
    }
     
    $where =  ' WHERE ' . implode(' AND ', $where);
    $order = ' ORDER BY annonce.date_annonce DESC'.
    $limit =  ' LIMIT '.$depart.','.$annoncesParPage;
     
    $stmt = $bdd->prepare($select . $where . $order . $limit);
    $stmt->execute(array($param));
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  7. #7
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2012
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

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

    Informations forums :
    Inscription : Mai 2012
    Messages : 14
    Points : 9
    Points
    9
    Par défaut
    Salut! le lien que je vous ai envoyé c est un site de refference ...au fait avec ce script ça me donne cette erreur
    Notice: Array to string conversion

  8. #8
    Modératrice
    Avatar de Celira
    Femme Profil pro
    Développeuse PHP/Java
    Inscrit en
    Avril 2007
    Messages
    8 633
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Développeuse PHP/Java
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2007
    Messages : 8 633
    Points : 16 372
    Points
    16 372
    Par défaut
    sab' s'est un peu emmêlé dans les tableaux. L'exécution de la requête devrait être $stmt->execute($param); et pas $stmt->execute(array($param));.
    Modératrice PHP
    Aucun navigateur ne propose d'extension boule-de-cristal : postez votre code et vos messages d'erreurs. (Rappel : "ça ne marche pas" n'est pas un message d'erreur)
    Cherchez un peu avant poser votre question : Cours et Tutoriels PHP - FAQ PHP - PDO une soupe et au lit !.

    Affichez votre code en couleurs : [CODE=php][/CODE] (bouton # de l'éditeur) et [C=php][/C]

  9. #9
    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
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  10. #10
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2012
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

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

    Informations forums :
    Inscription : Mai 2012
    Messages : 14
    Points : 9
    Points
    9
    Par défaut
    Bonjour tout le monde à propos de mon probleme tout est réglé maintenant juste avec ces quelques codes j'ai pu resoudre mon souci. Merci pour votre soutien
    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
     
    if(isset($_GET['submit'])){
     
        extract($_GET);
     
        $i = 0;
     
            $titre = $_GET['titre'];
            $cat = $_GET['cat'];
            $ville_ad =$_GET['ville_ad'];
     
        if(isset($titre)) { $choix[$i++] = "annonce.titre_annonce LIKE '%$titre%'"; }
        if(isset($cat)) { $choix[$i++] = "categorie.libele_cat LIKE '%$cat%'"; }
        if(isset($ville_ad)) { $choix[$i++] = "annonce.ville_annonce LIKE '%$ville_ad%'"; }
        $critere = $choix[0]." ";
     
        for($j=1;$j<$i;$j++)
                    {
                             $critere .= " AND ".$choix[$j]." ";
                     } 
        if($i > 0)
         {
            $sql = ("SELECT tbl_users.userID, tbl_users.userType, annonce.*, categorie.id_categorie, typecat.* FROM annonce INNER JOIN tbl_users ON annonce.user_id = tbl_users.userID INNER JOIN categorie ON categorie.id_categorie = annonce.categorie_id INNER JOIN typecat ON typecat.categorie_id = categorie.id_categorie WHERE $critere ORDER BY annonce.date_annonce DESC LIMIT ".$limit_start.','.$pagination);
            // Requête SQL
            $resultat = mysql_query($sql);
         }
     
    }

    Bien à vous!

  11. #11
    Expert éminent sénior
    Avatar de rawsrc
    Homme Profil pro
    Dev indep
    Inscrit en
    Mars 2004
    Messages
    6 142
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Dev indep

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 142
    Points : 16 545
    Points
    16 545
    Billets dans le blog
    12
    Par défaut
    Salut,

    n'utilise JAMAIS extract() sur $_GET, tiens lis un peu la doc par ici et surtout attarde toi sur les avertissements.

  12. #12
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2012
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

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

    Informations forums :
    Inscription : Mai 2012
    Messages : 14
    Points : 9
    Points
    9
    Par défaut
    Salut merci pour l'avertissement ...et si j'utilise
    ce code ? mysql_real_escape_string($critere) genre...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
     $sql = ("SELECT tbl_users.userID, tbl_users.userType, annonce.*, categorie.id_categorie, typecat.* FROM annonce INNER JOIN tbl_users ON annonce.user_id = tbl_users.userID INNER JOIN categorie ON categorie.id_categorie = annonce.categorie_id INNER JOIN typecat ON typecat.categorie_id = categorie.id_categorie WHERE $critere ORDER BY annonce.date_annonce DESC LIMIT ".$limit_start.','.$pagination, mysql_real_escape_string($critere));
    Bien à vous

  13. #13
    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
    mysql_real_escape_string() va sur chaque valeur, pas sur l'ensemble de la chaine :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    $critere = $choix[0]." ";
    for($j=1;$j<$i;$j++)
                    {
                             $critere .= " AND ".$choix[$j]." ";
                     }
    =>
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $choix = array_map('mysql_real_escape_string', $_GET['choix']);
    $critere = implode(' AND ', $choix);
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  14. #14
    Expert éminent sénior
    Avatar de rawsrc
    Homme Profil pro
    Dev indep
    Inscrit en
    Mars 2004
    Messages
    6 142
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Dev indep

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 142
    Points : 16 545
    Points
    16 545
    Billets dans le blog
    12
    Par défaut
    Il vaudrait beaucoup mieux que tu tâches de comprendre le code du collègue sabotage message 6, il est nickel.

    En utilisant les fonction mysql_xxx dépréciées, cela donnerait quelque chose dans ce genre :
    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
    if (isset($_GET['submit']))
    {
        $where = [];
     
        if ( ! empty($_GET['titre']))
        {
            $where[] = "annonce.titre_annonce LIKE '%".mysql_real_escape_string($_GET['titre'])."%'";
        }
     
        if ( ! empty($_GET['cat']))
        {
            $where[] = "categorie.libele_cat LIKE '%".mysql_real_escape_string($_GET['cat'])."%'";
        }
     
        if ( ! empty($_GET['ville_ad']))
        {
            $where[] = "annonce.ville_annonce LIKE '%".mysql_real_escape_string($_GET['ville_ad'])."%'";
        }
     
        if ( ! empty($where))
        {
            $sql_where = implode(' AND ', $where);
            $sql       = <<<sql
    SELECT
        tbl_users.userID, tbl_users.userType, annonce.*, categorie.id_categorie, typecat.*
    FROM
        annonce
            INNER JOIN tbl_users ON annonce.user_id = tbl_users.userID
            INNER JOIN categorie ON annonce.categorie_id = categorie.id_categorie 
                INNER JOIN typecat ON categorie.id_categorie = typecat.categorie_id 
    WHERE
        {$sql_where}
    ORDER BY
        annonce.date_annonce DESC
    LIMIT {$limit_start}, {$pagination}
    sql;
     
            $resultat = mysql_query($sql);
        }
     
        $resultat = [];
    }

  15. #15
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2012
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

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

    Informations forums :
    Inscription : Mai 2012
    Messages : 14
    Points : 9
    Points
    9
    Par défaut
    Es ce que par hasard ya pas une erreur dans ton code ? car il s execute pas
    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
     
    $sql       = <<<sql
    SELECT
        tbl_users.userID, tbl_users.userType, annonce.*, categorie.id_categorie, typecat.*
    FROM
        annonce
            INNER JOIN tbl_users ON annonce.user_id = tbl_users.userID
            INNER JOIN categorie ON annonce.categorie_id = categorie.id_categorie 
                INNER JOIN typecat ON categorie.id_categorie = typecat.categorie_id 
    WHERE
        {$sql_where}
    ORDER BY
        annonce.date_annonce DESC
    LIMIT {$limit_start}, {$pagination}
    sql;
     
            $resultat = mysql_query($sql);
        }
     
        $resultat = [];

  16. #16
    Expert éminent sénior
    Avatar de rawsrc
    Homme Profil pro
    Dev indep
    Inscrit en
    Mars 2004
    Messages
    6 142
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Dev indep

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 142
    Points : 16 545
    Points
    16 545
    Billets dans le blog
    12
    Par défaut
    Oui commente le dernier $resultat = []

  17. #17
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2012
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

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

    Informations forums :
    Inscription : Mai 2012
    Messages : 14
    Points : 9
    Points
    9
    Par défaut
    Désolé mais j'ai pas compris

    Bien à vous

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

Discussions similaires

  1. [MySQL] problème avec mon application de recherche php/mysql
    Par cuisto44000 dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 05/06/2008, 04h01
  2. problème avec la barre de navigation en PHP
    Par L'aigle de Carthage dans le forum Langage
    Réponses: 3
    Dernier message: 28/03/2008, 10h00
  3. [PHP-JS] problème avec la balise href dans php
    Par metrax dans le forum Langage
    Réponses: 5
    Dernier message: 02/05/2007, 11h06
  4. Problème avec une Barre de Progression
    Par hugo69 dans le forum Access
    Réponses: 1
    Dernier message: 15/12/2006, 16h37
  5. [SQL-Server] Problème avec la fonction mssql_connect (connexion PHP SQL Server)
    Par flydragon dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 24/05/2006, 12h59

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