j essey de faire un moteur de recherche , et ça me donne l erreur suivante
Erreur : SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table-moteur-de-recherche WHERE motclef LIKE "%inpt%" OR "%ensem%" OR 1=0' at line 1
voici mon code :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
<title>Elements trouvés:</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
if(isset($_POST['text-recherche']))// on recupere ce que l utilisateur a tappé
{
$rec = htmlentities($_POST['text-recherche']);// pour recuperer
}
else
{
$rec = 'php MYSQL';
}
?>
<?php
$mots = explode(' ',$rec);//En separre lexpression en mots cles
?>
<?php
// Connexion à la base de données
try
{
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO('mysql:host=localhost;dbname=moteur-de-recherche', 'root', '', $pdo_options);
$req = "SELECT * FROM table-moteur-de-recherche WHERE motclef LIKE ";
foreach($mots as $mot)
{
$req .= ' "%'.$mot.'%" OR';// c est la ligne de l erreur :(
}
$req .= ' 1=0';
$reponse = $bdd->query($req );
?>
<?php
// Récupération des lignes rechérché
$i=0;
$reponse = $bdd->query($req);
while ($donnees = $reponse->fetch())
{$i=1;
?>
<table>
<tr>
<td><?php echo $donnees['titre']; ?></td>
<td><?php echo $donnees['description']; ?></td>
<td><?php echo $donnees['URL']; ?></td>
</tr>
</table>
<?php
}
?>
<?php
if(i)
{
echo "Essayer autre chose svp " ;}
?>
<?php
$reponse->closeCursor();
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
?>
<p>
</p>
</body>
</html>
mercii d avance si vous avez des remarque ou une solution :)