Moteur de recherche en php et concaténation requêt
nestorinfo
Messages postés
5
Statut
Membre
-
yg_be Messages postés 23541 Date d'inscription Statut Contributeur Dernière intervention -
yg_be Messages postés 23541 Date d'inscription Statut Contributeur Dernière intervention -
Salut à tous , je suis un vrais debutant en php
J'essaie de faire un moteur de recherche pour mon site mais j'ai une erreur dans mon code que je n'ai pas su résoudre :
voici le message d'erreur
Fatal error: Call to a member function fetch() on a non-object in C:\wamp\www\test\form_recherche.php on line 47
J'essaie de faire un moteur de recherche pour mon site mais j'ai une erreur dans mon code que je n'ai pas su résoudre :
<?php
include("connexion.php");
$info=$conn->query('SELECT client,axe,cylindre,sphere,addition,axe1,cylindre1,sphere1,addition1,date FROM info ')or die(print_r($conn->erroInfo()));
if (isset($_GET['query']) AND !empty($_GET['query']))
{
$query=htmlspecialchars($_GET['query']);
$info=$conn->query=('SELECT client ,axe ,cylindre,sphere,addition,axe1,cylindre1,sphere1,addition1,date FROM info WHERE
client,axe,cylindre,sphere,addition,axe1,cylindre1,sphere1,addition1,date LIKE "%'.$query.'%"' );
}
?>
<!DOCTYPE html>
<html >
<head>
<title>Moteur de recherche</title>
</head>
<body >
<form method="GET" >
<h2 align="left" >
Entrer votre recherche: <input type="search" name="query" maxlength="80" size="80" >
<input type="submit" value="rechercher">
<ul>
<?php while ( $a = $info->fetch()) { ?>
<li>
<?=$a['client']?> <?=$a['axe']?> <?=$a['cylindre']?> <?=$a['sphere']?> <?=$a['addition']?> <?=$a['axe1']?> <?=$a['cylindre1']?> <?=$a['sphere1']?>
<?=$a['addition1']?> <?=$a['date']?>
</li>
<?php } ?>
</ul>
</h2>
</form>
</body>
</html>
voici le message d'erreur
Fatal error: Call to a member function fetch() on a non-object in C:\wamp\www\test\form_recherche.php on line 47
A voir également:
- Moteur de recherche en php et concaténation requêt
- Google moteur de recherche page d'accueil - Guide
- Copernic moteur de recherche - Télécharger - Navigateurs
- Recherche automatique des chaînes ne fonctionne pas - Guide
- Recherche de pairs utorrent ✓ - Forum Téléchargement
- Moteur de recherche yahoo revient toujours ✓ - Forum Virus
1 réponse
Bonjour,
Le message d'erreur vient du fait que ta requête ne retourne rien.... car elle est fausse
Regarde donc à quoi sert la fonction CONCAT
https://www.w3schools.com/sql/func_mysql_concat.asp
NB: Teste TOUJOURS tes requêtes DIRECTEMENT dans ta BDD (via PHPMyadmin par exemple) AVANT de vouloir les mettre dans ton code PHP.
ça te permettra de savoir si elles fonctionnent ou non.
Le message d'erreur vient du fait que ta requête ne retourne rien.... car elle est fausse
'SELECT client ,axe ,cylindre,sphere,addition,axe1,cylindre1,sphere1,addition1,date FROM info WHERE client,axe,cylindre,sphere,addition,axe1,cylindre1,sphere1,addition1,date LIKE "%'.$query.'%"'
Regarde donc à quoi sert la fonction CONCAT
https://www.w3schools.com/sql/func_mysql_concat.asp
NB: Teste TOUJOURS tes requêtes DIRECTEMENT dans ta BDD (via PHPMyadmin par exemple) AVANT de vouloir les mettre dans ton code PHP.
ça te permettra de savoir si elles fonctionnent ou non.
voici le code
<?php include("connexion.php"); $info=$conn->query('SELECT client FROM info ')or die(print_r($conn->erroInfo())); if (isset($_GET['q']) AND !empty($_GET['q'])) { $q= htmlspecialchars($_GET['q']); $info =$conn->query('SELECT client FROM info WHERE client LIKE "%.$q.%"' ); } ?> <!DOCTYPE html> <html > <head> <title>Moteur de recherche</title> </head> <body > <form method="GET" > <h2 align="left" > Entrer votre recherche: <input type="search" name="q" maxlength="80" size="80" > <input type="submit" value="rechercher"> <ul> <?php while ( $a = $info->fetch()) { ?> <li> <?=$a['client']?> </li> <?php } ?> </ul> </h2> </form> </body> </html>EDIT : Correction des BALISES DE CODE ( encore )
$info =$conn->query('SELECT client FROM info WHERE client LIKE "%'.$q.'%"') or die(print_r($conn->erroInfo()));;