Jump to content

Search Engine : Error


yash87

Recommended Posts

Hi, Im trying to do a search engine. However, im facing this errors.. Anyone can help..

 

Error :

 

Notice: Undefined variable: searching in C:\wamp\www\i-document\s.php on line 17

 

Thankz in advance.

 



<h2>Search Form</h2>

<form name="search" method="post" action="s.php">
  Seach for: <input type="text" name="find" /> in
  <Select NAME="field">
    <Option VALUE="file_name">File Name</option>
    <Option VALUE="year">Year</option>
    <Option VALUE="downer">Owner</option>
        <
  </Select>

  <input type="hidden" name="searching" value="yes" />
  <input type="submit" name="search" value="Search" />
</form>

<?php
  if ($searching =="yes"){
    echo "<h3>Search Results</h3><p>";
    if ($find == ""){
      echo "<p>Please Enter a search term";
      exit;
    }
   
    include "config.php";
    $find = strtoupper($find);
    $find = strip_tags($find);
    $find = trim ($find);

    $query = mysql_query("SELECT * FROM document WHERE upper($field) LIKE'%$find%'");
    while($result = mysql_fetch_array($query)){
      echo $result['file_ref'];
      echo " ";
      echo $result['file_name'];
      echo "<br>";
      echo $result['owner'];
      echo "<br>";
      echo "<br>";
    }

    $matches=mysql_num_rows($query);
    if ($matches == 0){
      echo "Sorry, we can not find an entry to match your query<br><br>";
    }

    echo "<b>Searched For:</b> " .$find;
  }
?>



Link to comment
https://forums.phpfreaks.com/topic/216353-search-engine-error/
Share on other sites

You are calling a variable that doesn't exist. You should check to make sure it exists before you use it:

 

if( empty($searching) === false && $searching =="yes" )
{
    echo "<h3>Search Results</h3><p>";
    if ($find == ""){
      echo "<p>Please Enter a search term";
      exit;
    }
   
    include "config.php";
    $find = strtoupper($find);
    $find = strip_tags($find);
    $find = trim ($find);

    $query = mysql_query("SELECT * FROM document WHERE upper($field) LIKE'%$find%'");
    while($result = mysql_fetch_array($query)){
      echo $result['file_ref'];
      echo " ";
      echo $result['file_name'];
      echo "<br>";
      echo $result['owner'];
      echo "<br>";
      echo "<br>";
    }

    $matches=mysql_num_rows($query);
    if ($matches == 0){
      echo "Sorry, we can not find an entry to match your query<br><br>";
    }

    echo "<b>Searched For:</b> " .$find;
}

Link to comment
https://forums.phpfreaks.com/topic/216353-search-engine-error/#findComment-1124298
Share on other sites

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.