View Single Post
Old Mar 26th, 2008, 1:18 PM   #1
Arnack
Programmer
 
Join Date: Jul 2005
Posts: 66
Rep Power: 3 Arnack is on a distinguished road
Simple PHP Search Script

I put this all on index.php:
PHP Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <title>arnack.com Gaming Wesbite Database</title>
  4. </head>
  5. <body>
  6. <h2>Search</h2>
  7. <form name="search" method="post" action="<?=$PHP_SELF?>">
  8. Seach for: <input type="text" name="find" /> in
  9. <Select NAME="field">
  10. <Option VALUE="fname">First Name</option>
  11. <Option VALUE="lname">Last Name</option>
  12. <Option VALUE="info">Profile</option>
  13. </Select>
  14. <input type="hidden" name="searching" value="yes" />
  15. <input type="submit" name="search" value="Search" />
  16. </form>
  17. <?
  18. error_reporting(E_ALL);
  19. //This is only displayed if they have submitted the form
  20. if ($searching =="yes")
  21. {
  22. echo "<h2>Results</h2><p>";
  23.  
  24. //If they did not enter a search term we give them an error
  25. if ($find == "")
  26. {
  27. echo "<p>You forgot to enter a search term";
  28. exit;
  29. }
  30. // Otherwise we connect to our Database
  31. mysql_connect("localhost", "arnackco_Arnack", "oompa123") or die(mysql_error());
  32. mysql_select_db("arnackco_search") or die(mysql_error());
  33.  
  34. // We preform a bit of filtering
  35. $find = strtoupper($find);
  36. $find = strip_tags($find);
  37. $find = trim ($find);
  38.  
  39. //Now we search for our search term, in the field the user specified
  40. $data = mysql_query("SELECT * FROM users WHERE upper($field) LIKE'%$find%'");
  41.  
  42. //And we display the results
  43. while($result = mysql_fetch_array( $data ))
  44. {
  45. echo $result['fname'];
  46. echo " ";
  47. echo $result['lname'];
  48. echo "<br>";
  49. echo $result['info'];
  50. echo "<br>";
  51. echo "<br>";
  52. }
  53.  
  54. //This counts the number or results - and if there wasn't any it gives them a little message explaining that
  55. $anymatches=mysql_num_rows($data);
  56. if ($anymatches == 0)
  57. {
  58. echo "Sorry, but we can not find an entry to match your query<br><br>";
  59. }
  60.  
  61. //And we remind them what they searched for
  62. echo "<b>Searched For:</b> " .$find;
  63. }
  64. ?>
  65. </body>
  66. </html>
Problem is outputed as:
Notice: Undefined variable: searching in /home/arnackco/public_html/index.php on line 20

Any help please?
__________________
Ack Network
*UNDER CONSTRUCTION*
Now hiring staff of all sorts.

Last edited by big_k105; Mar 26th, 2008 at 1:23 PM. Reason: changed ICODE tag to CODE=PHP tag
Arnack is offline   Reply With Quote