cc,
je vient de réaliser un moteur de recherche avec une liste déroulante dans un formulaire (index.php) et le résultat s'affiche dans search.php;
Je souhaiterai que la recherche et le résultat soient sur la meme page .
Comment dois je procéder? Que me conseillez vous?
Merci

index.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
 
 
 <?php
 $serveur='localhost';
 $user='root';
 $motdepasse=''; 
 $bdd='moteur';
 $connect= mysql_connect($serveur,$user,$motdepasse) or die ("Impossible de se connecter: "); 
 mysql_select_db($bdd);
 
?> 
 
 
<!DOCTYPE html>
<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
<head>
  <title></title>
</head>
<body>
  <div id="content">
 
    <form action="index.php" method="post">
 
      <label for="search">Rechercher :</label>
 
 
<select name="search" >
 
<?php
 
$result = mysql_query("SELECT titre FROM moteur");
while ($row = mysql_fetch_array($result))
{
 
echo '<option value="'.$row["titre"].'">'.$row["titre"].'</option>';
 
}
 
?>
 
      <input type="submit" value="Rechercher" />
 
    </form>
</body>
</html>
search.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
 
 
<?php
 
if(empty($_POST) || empty($_POST['search']))
{
  header('Location: index.php');
}
else
{
  extract($_POST);
}
 
 
 
?>
 
<!DOCTYPE html>
<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
<head>
  <title></title>
</head>
<body>
  <div id="content">
    <h3>Resultat pour <strong><?php echo $search;?></strong> :</h3>
 
    <?php
 
    try{
    $bdd = new PDO('mysql:host=localhost;dbname=moteur', 'root', '') or die(print_r($bdd->errorInfo()));
    $bdd->exec('SET NAMES utf8');
    }
 
    catch(Exeption $e){
    die('Erreur:'.$e->getMessage());
    }
 
    $req = $bdd->query("SELECT * FROM moteur WHERE titre LIKE '%$search%' OR contenu LIKE '%$search%' ORDER BY id");
    if($req->rowCount()>0)
    {
      while($data = $req->fetch(PDO::FETCH_OBJ))
      {
        echo '<h2>'.$data->titre.'</h2>';
        echo '<p>'.$data->contenu.'</p>';
      }
    }
    else
    {
      echo '<h2>Aucun resultat</h2>';
    }
 
 
    ?>
 
 
    <br />
    <br />
    <p><a href="index.php">Accueil</a></p>
 
  </div>
</body>
</html>