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
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);

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.