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 :

Undefined variable: search


Sujet :

PHP & Base de données

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2014
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2014
    Messages : 4
    Par défaut Undefined variable: search
    svp si qlq 1 a une idee , le projet fonctionne sauf , quand je veux rechercher il m affiche l erreur suivante : Undefined variable: search in C:\wamp\www\48720-1256465-g-sav-le-gestionnaire-des-maintenances-informatiques\G-Sav_free\recherche.php on line 19

    voila :
    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
    <?php
    include("includes/header.php");
     
    //Get variables from includes/config.php to connect to mysql server
    require 'includes/config.php';
     
    // connect to the mysql database server.
    mysql_connect ($hostname, $user, $pass);
    //select the database
    mysql_select_db($dbase) or die('Cannot select database');
     
    //search variable = data in search box or url
    if(isset($_GET['search']))
    {
    $search = $_GET['search'];
    }
     
    //trim whitespace from variable
    //Ligne 19
    $search = trim($search);
    $search = preg_replace('/\s+/', ' ', $search);
     
    //seperate multiple keywords into array space delimited
    $keywords = explode(" ", $search);
     
    //Clean empty arrays so they don't get every row as result
    $keywords = array_diff($keywords, array(""));
     
    //Set the MySQL query
    if ($search == NULL or $search == '%'){
    } else {
    for ($i=0; $i<count($keywords); $i++) {
    $query = "SELECT * FROM fiche " .
    "WHERE nom LIKE '%".$keywords[$i]."%'".
    " OR id LIKE '%".$keywords[$i]."%'" .
    " OR date LIKE '%".$keywords[$i]."%'" .
    " OR prenom LIKE '%".$keywords[$i]."%'" .
    " ORDER BY nom";
    }
     
    //Store the results in a variable or die if query fails
    $result = mysql_query($query) or die(mysql_error());
    }
    if ($search == NULL or $search == '%'){
    } else {
    //Count the rows retrived
    $count = mysql_num_rows($result);
    }
     
    echo "<body onLoad=\"self.focus();document.searchform.search.focus()\">";
    echo "<center><table border=\"0\" class=\"table\">";
    echo "   <tr>";
    echo "      <td class=\"titre\">RECHERCHER</td>";
    echo "   </tr>";
    echo "</table></center>";
    echo "<table border=\"0\">";
    echo "   <tr>";
    echo "      <td><font color=\"#000000\">Vous pouvez effectuer une recherche par N�, Nom, Pr�nom, Date ou tout autres mots cl�s pr�sent dans une fiche !</font></td>";
    echo "   </tr>";
    echo "</table>";
    echo "<br /><center><form name=\"searchform\" method=\"GET\" action=\"recherche.php\">";
    echo "<input type=\"text\" name=\"search\" size=\"20\" TABINDEX=\"1\" />";
    echo " <input type=\"submit\" value=\"Rechercher\" />";
    echo "</form>";
    //If search variable is null do nothing, else print it.
    if ($search == NULL) {
    } else {
    echo "Resultat de recherche pour : <b><FONT COLOR=\"blue\">";
    foreach($keywords as $value) {
       print "$value ";
    }
    echo "</font></b>";
    }
    echo "</center>";
     
    //If users doesn't enter anything into search box tell them to.
    if ($search == NULL){
    echo "<center><b><FONT COLOR=\"red\">Merci d'entrez un mots cl�
        .</font></b><br /></center>";
    } elseif ($search == '%'){
    echo "<center><b><FONT COLOR=\"red\">Merci d'entrez un mots cl�.</font></b><br /></center>";
    //If no results are returned print it
    } elseif ($count <= 0){
    echo "<center><b><FONT COLOR=\"red\">Aucun r�sultat dans la base de donn�e.</font></b><br /></center>";
    } else {
    echo "<table border=\"0\">";
    echo "	<tr>";
    echo "		<td width=\"200\"><b><font color=\"#000000\">Nom</font></td>";
    echo "		<td width=\"200\"><b><font color=\"#000000\">Pr�nom</font></td>";
    echo "		<td width=\"200\"><b><font color=\"#000000\">Date</font></td>";
    echo "	</tr>";
    echo "</table></center>";
    while($row = mysql_fetch_array($result))
    {
    echo "<center><table border=\"0\">";
    echo "	<tr>";
    echo "		<td width=\"200\"><font color=\"#000000\"><a href=\"fiche.php?id=".$row['id']." \"> ".$row['nom']."</a></font></td>";
    echo "		<td width=\"200\"><font color=\"#000000\"><a href=\"fiche.php?id=".$row['id']." \"> ".$row['prenom']."</a></font></td>";
    echo "		<td width=\"200\"><font color=\"#000000\"><a href=\"fiche.php?id=".$row['id']." \"> ".$row['date']."</a></font></td>";
    echo "	</tr>";
    echo "</table></center>";
    //end while
    }
    //end if
    }
     
    echo "</body>";
    echo "</html></div>";
    if ($search == NULL or $search == '%') {
    } else {
    //clear memory
    mysql_free_result($result);
    }
    include("includes/footer.php");
    ?>

  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
    Par défaut
    Il faut que tu gères le cas ou $_GET['search'] n'existe pas.
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

Discussions similaires

  1. Undefined variable: Idclic
    Par kratos59 dans le forum Langage
    Réponses: 7
    Dernier message: 11/05/2006, 16h50
  2. Notice: Undefined variable
    Par oranoutan dans le forum Langage
    Réponses: 19
    Dernier message: 21/12/2005, 22h28
  3. undefined variable
    Par ept35 dans le forum Langage
    Réponses: 3
    Dernier message: 30/11/2005, 15h48
  4. Notice: Undefined variable
    Par kayn dans le forum Langage
    Réponses: 2
    Dernier message: 03/10/2005, 20h44
  5. Réponses: 3
    Dernier message: 22/09/2005, 11h24

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