Bonjour,
je suis entrain de réaliser une galerie de photos pour mon projet CSW.
Et je dois réaliser une fonction rechercher qui me permet de chercher les photos de la BDD MySQL par catégorie ou par titre et les afficher. Mais j'ai un problème. Voici mes codes sources:
Fonction rechercher:
Fonction srch:
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 <?php // Paramètres de connexion $hostname_dbprotect = "localhost"; // nom ou ip de notre serveur $database_dbprotect = "galerie_photos"; // nom de notre base de données $username_dbprotect = "root"; $password_dbprotect = ""; //$id_photo = $_GET['id_photo']; $dbprotect = mysql_pconnect($hostname_dbprotect, $username_dbprotect, $password_dbprotect) or trigger_error(mysql_error(),E_USER_ERROR); $selection_de_la_base=mysql_select_db($database_dbprotect,$dbprotect) or die(mysql_error()); ?> <? include("top.inc.php"); ?> <html> <head> <title>Recherche d'une photo</title> </head> </html> <body> <center> <h2>Search</h2> <form method="post" action="srch.php"> Seach for: <input type="text" name="find" maxlength=255 /> in <Select NAME="field"> <Option VALUE="categorie">Catégorie</option> <Option VALUE="titre_photo">Titre</option> </Select> <input type="hidden" name='searching' value="yes" /> <input type="submit" name="search" value="Search" /> </form> <div style="text-align: center;"> <br style="font-weight: bold;"> </div> </center> </body>
Le problème avec mon code c'est qu'on j'exécute (essaye de chercher une photo, je rentre par ex nature, et je clique sur search) il me met
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 <? //This is only displayed if they have submitted the form if ($searching =="yes") { echo "<h2>Results</h2><p>"; //If they did not enter a search term we give them an error if ($find == "") { echo "<p>You forgot to enter a search term"; exit; } // Otherwise we connect to our Database mysql_connect("localhost", "root", "password") or die(mysql_error()); mysql_select_db("galerie_photos") or die(mysql_error()); // We preform a bit of filtering $find = strtoupper($find); $find = strip_tags($find); $find = trim ($find); //Now we search for our search term, in the field the user specified $data = mysql_query("SELECT * FROM photo WHERE upper($field) LIKE'%$find%'"); //And we display the results while($result = mysql_fetch_array( $data )) { echo $result['categorie']; echo " "; echo $result['titre_photo']; echo "<br>"; echo "<br>"; } //This counts the number or results - and if there wasn't any it gives them a little message explaining that $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query<br><br>"; } //And we remind them what they searched for echo "<b>Searched For:</b> " .$find; } ?>J'ai essayé un 2ème code mais toujours le même pbm.
Code : Sélectionner tout - Visualiser dans une fenêtre à part Notice: Undefined variable: searching in c:\program files\easyphp1-8\www\galerie\srch.php on line 5Est ce que quelqu'un a une idée? Merci bcp de votre aide.
Bonne journée.
Partager