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
| <!DOCTYPE html>
<html>
<head>
<title> Moteur de recherche</title>
<meta charset ='UTF-8'/>
</head>
<body>
<?php
if(isset($_POST['query']) && !empty($_POST['query']))
{
$query= preg_replace("#[^a-z?0-9]#i","",$_POST['query']);
$sql= "SELECT id,prenom AS title FROM clients WHERE prenom LIKE ? OR nom LIKE ?";
//conncxion a la base de données
include("fspeciales/connecter.php");
$req = $connex->prepare($sql);
$req->execute(array('%'.$query.'%','%'.$query.'%'));
$count = $req->rowcount();
if($count >= 1)
{
echo "$count le(s) résultat(s) trouvé(s)pour <strong>$query</strong> </hr>";
while ($data = $req->fetch(PDO::FETCH_OBJ))
{
echo "#".$data->id.'- Titre: '.$data->prenom;
}
}
else
{
echo"0 resultat trouvé pour votre recherche :<strong>$query</strong></hr>";
}
}
?>
<form action= "<?php echo $_SERVER['PHP_SELF']; ?> " methode= "post ">
<br>
<br>
<label for= "query " >Entrez votre recherche :</label>
<input type= "search" name= "query" maxlength= "80" size= "80" id= "query"/>
<input type= "submit" value= "Rechercher">
</form>
</body>
</html> |
Partager