JuttyMire Posted September 20, 2009 Share Posted September 20, 2009 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); ?> Quote Link to comment Share on other sites More sharing options...
ozestretch Posted September 20, 2009 Share Posted September 20, 2009 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); ?> Quote Link to comment Share on other sites More sharing options...
JuttyMire Posted September 20, 2009 Author Share Posted September 20, 2009 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. Quote Link to comment Share on other sites More sharing options...
ozestretch Posted September 20, 2009 Share Posted September 20, 2009 It wasn't displaying 'old' results... as the search term was not defined, it returned ALL results (I assume) Use the code I gave above and test it Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.