Erreur php

Résolu
Bonjour,voil la mon erreur
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 '%%' at line 1
<html>
<form method="POST" action="">
Rechercher un mot : <input type="text" name="recherche">
<input type="SUBMIT" value="Search!">
</form>
</html>
<?php
//connection au serveur:
$cnx = mysql_connect( "localhost", "root", "" ) ;
// Récupère la variable
$recherche = isset($_POST['recherche']) ? $_POST['recherche'] : '';
// la requete mysql
$sql = mysql_query("SELECT name FROM spip_fuaj_adherents WHERE name LIKE %$recherche%") or die (mysql_error());

// affichage du résultat
while(list($name)=mysql_fetch_array($sql)){
echo 'Resultat de la recherche: '.$name.' <br />';
}

?>Bonjour,voil la mon erreur
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 '%%' at line 1 <html>
<form method="POST" action="">
Rechercher un mot : <input type="text" name="recherche">
<input type="SUBMIT" value="Search!">
</form>
</html> <?php
//connection au serveur:
$cnx = mysql_connect( "localhost", "root", "" ) ;
// Récupère la variable
$recherche = isset($_POST['recherche']) ? $_POST['recherche'] : '';
// la requete mysql
$sql = mysql_query("SELECT name FROM spip_fuaj_adherents WHERE name LIKE %$recherche%") or die (mysql_error());

// affichage du résultat
while(list($name)=mysql_fetch_array($sql)){
echo 'Resultat de la recherche: '.$name.' <br />';
}

?>
Configuration: Windows XP
Internet Explorer 7.0

5 réponses

  1. mon moteur ne m 'affiche que la table nom , mais moi je voudrais tout les champs
    1. A ce moment là fait un select *
  2. Contributeur
    Bon déjà il récupère la bonne valeur :p

    Maintenant rajoute des simple quote ( ' ) autour les %

    Comme ça :

    "SELECT name FROM spip_fuaj_adherents WHERE name LIKE '%" . $recherche . "%'"
    1. maintenant il m 'affiche

      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 '%aaaaaaaaaaaaa%' at line 1

      avec aaaaaaaaa c 'est la valeur que j 'aii tapé dans le formulaire
      1. Contributeur
        Remplace :

        "SELECT name FROM spip_fuaj_adherents WHERE name LIKE %$recherche%"

        Par

        "SELECT name FROM spip_fuaj_adherents WHERE name LIKE %" . $recherche . "%"

        Là PHP trouvait "$recherche" dans ta requête et non pas sa valeur.

        Essaie et dis moi si tu as encore l'erreur