Jump to content
Sign in to follow this  
toulousain3117

Moteur de Recherche membre php

Rate this topic

Recommended Posts

Bonjour, je recherche un moteur de recherche qui permet de rechercher des membres dans la BDD mysql .

j'ai déjà un script mais il ne marche pas .

Voilà déjà la premiere page de mon script. c'est le formulaire du moteur de recherche, de la page search.php .

<?php include("sources/config.php"); ?>
<?
if(isset($search))
{

if (empty($search))
{
echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL = ?msg=Veuillez+saisir+un+mot+clé+!\">";
exit;
}

if (strlen($search) < 2)
{
echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL = ?msg=Le+mot+clé+doit+comporter+au+minimum+2+caractères+!\">";
exit;
}

$expiration = 3600;
setcookie("cooksrch",$search,time()+$expiration);
Header("Location: result.php");

}
?><form action="result.php" method="post" name="search" id="search">
<table width="89%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#798FA6">
<tr>
<td bgcolor="#F1F3F5"><table width="100%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td height="25"><div align="center" class="Style1">Entrer au minimum 2 caractères</div></td>
</tr>
<tr>
<td height="25"><div align="center">
<input name="search" type="text" class="txt_box" id="search" value="<? echo "$cooksrch"; ?>" size="50">
</div></td>
</tr>
<tr>
<td height="25"><div align="center">
<input name="Submit" type="submit" class="txt_box" value=" Valider ">
</div></td>
</tr>
</table></td>
</tr>
</table>
</form>

Et voilà celui de la page result.php :

<?php include("sources/config.php"); ?>
<?php

if(isset($cooksrch))
{
$search2 = str_replace("+"," ",$cooksrch);
$search2 = trim($search2);

while(strpos($search2," "))
{
$search2 = str_replace(" "," ",$search2);
}
}

function notag($search2)
{
$pattern = "<[^>]+>";
$temp = ereg_replace($pattern,"",$search2);
$temp = str_replace("\n"," ",$temp);

while(STRPOS($temp," "))
{
$temp = STR_REPLACE(" "," ",$temp);
}
return($temp);
}

if(isset($search2))
{
$db = mysql_connect($host,$user,$pass);
mysql_select_db($base,$db);

$SQL = "SELECT * FROM comptes";
$SQL .= " WHERE nom LIKE '%";
$espace = "%' AND nom LIKE '%";
$SQL .= str_replace(" ",$espace,$search2);
$SQL .= "%' ORDER BY nom DESC";
$result = mysql_query($SQL);
$num = mysql_num_rows($result);

if($num == "0")
{
echo "<div align=\"center\"><span class=\"Style5\">Aucun membres ne correspond à votre recherche</span></div><br>";
echo "<div align=\"center\"><a href=\"../index.php\">Nouvelle Recherche</a></div>";
}

while ($val = mysql_fetch_array($result))
{
?>

Voilà je n'arrive pas a trouver la faille . Vous pouvez m'aider svp ?

Share this post


Link to post
Share on other sites

bonjour,

j'ai testé ta requête, chez moi elle fonctionne maintenant, j'ai modifier LIKE en like

   
$SQL = "SELECT * FROM comptes";
$SQL .= " WHERE nom like '%";
$espace = "%' AND nom like '%";
$SQL .= str_replace(" ",$espace,$search2);
$SQL .= "%' ORDER BY nom DESC";
$result = mysql_query($SQL);
$num = mysql_num_rows($result);

éffectue un test et dit moi

Share this post


Link to post
Share on other sites

chez moi sa ne amrche pas au contraire sa me met une erreur

Warning: Cannot modify header information - headers already sent by (output started at /home/mass/web/www/EPS/search.php:2) in /****/****/****/****/****/search.php on line 20

Warning: Cannot modify header information - headers already sent by (output started at /home/mass/web/www/EPS/search.php:2) in /****/****/****/****/****/search.php on line 21

Share this post


Link to post
Share on other sites

Salut,

<?php include("sources/config.php"); ?>
<?

enleve ?> et <? qui sont inutile.

Le probléme vient du fait que tu envoies deja des "headers" avec la fonction setcookie avant de vouloir en renvoyer via la fonction header.

Share this post


Link to post
Share on other sites

Tu ne peux envoyer deux fois des headers sur une page php.

donc tu ne peux combiner setcookie et header.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...