aminagu
Messages postés47Date d'inscriptionmercredi 11 avril 2012StatutMembreDernière intervention26 août 2013
-
27 juil. 2011 à 02:53
aminagu
Messages postés47Date d'inscriptionmercredi 11 avril 2012StatutMembreDernière intervention26 août 2013
-
27 juil. 2011 à 11:24
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
<?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';
cod57
Messages postés1653Date d'inscriptiondimanche 7 septembre 2008StatutMembreDernière intervention11 septembre 201319 27 juil. 2011 à 10:05
remplace par ça aussi
si pas vide
si 2 car
et si il y a un output ...
<?php
$mots=array();
if(isset($_POST['text-recherche']) && !empty($_POST['text-recherche']) && strlen($_POST['text-recherche'])>2){
$rec = trim(htmlentities($_POST['text-recherche']));// pour recuperer
$mots = explode(' ',$rec);//En separre lexpression en mots cles