Jump to content

[SOLVED] php MYSql Search Function


JuttyMire

Recommended Posts

Hello,

 

I need help with this php MySql Search function I made.

 

It searches the database just fine, and returns results just fine.

 

Here comes the problem:  After the search is over, it returns the same results and when I do a second search it returns the same new results along with the old. Is there a way I can have it so it doesn't output the old text?

 

Sorry I'm kind of new to this.

 

<html>
<head>
	<title>Guid Search</title>
</head>

<body>
<form action="search.php" method="post">
  	 Search Your GuiD: <input type="text" name="username" /><br />
    <input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>


<?php
     

mysql_connect ("l*******", "****","****")  or die (mysql_error());
mysql_select_db ("******");

$find = strtoupper($username);
$find = strip_tags($username);
$find = trim ($username); 

$term = $_POST['username'];

$sql = mysql_query("select * from users where username like '%$username%'");
  
  
  while ($row = mysql_fetch_array($sql)){
echo '<br/> GuiD: '.$row['name'];
}
mysql_free_result($sql);

?>

 

Link to comment
https://forums.phpfreaks.com/topic/174843-solved-php-mysql-search-function/
Share on other sites

where are you defining $username?

 

$find and $term are not being used!? Should they define $username?

 

<html>
   <head>
      <title>Guid Search</title>
   </head>

   <body>
<form action="search.php" method="post">
      Search Your GuiD: <input type="text" name="username" /><br />
    <input type="submit" name="submit" value="Submit" />
   </form>
   </body>
</html>


<?php
     
    
mysql_connect ("l*******", "****","****")  or die (mysql_error());
mysql_select_db ("******");

$find = $_POST['username'];
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find); 



$sql = mysql_query("select * from users where username like '%$find%'");
     
     
     while ($row = mysql_fetch_array($sql)){
   echo '<br/> GuiD: '.$row['name'];
   }
   mysql_free_result($sql);

?>

Thank you for taking the time to reply.

I just now noticed I have unused varibles. I will make changes to that soon enough. Do you know what I could do to stop the page from displaying old results?  I did clear my browsers cache, and cookies. To no avail.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.