Page 1 of 1

Search Problem

Posted: Mon Oct 11, 2010 3:53 am
by shanz
Hi,
Im not sure how to correct these errors, can someone help me.

search.php

Notice: Undefined index: submit in C:\wamp\www\i-document\search.php on line 12

Notice: Undefined index: search in C:\wamp\www\i-document\search.php on line 13

After clicking 'search' :

Notice: Undefined variable: x in C:\wamp\www\i-document\search.php on line 39

Notice: Undefined variable: construct in C:\wamp\www\i-document\search.php on line 41

Thankz.

Code: Select all


<html>
<body>
   <form id="form1" method="GET" action="search.php">
        <table width="446" height="135" border="1" align="center">
          <tr>
            <td height="31" colspan="2" align="center" valign="middle" bgcolor="#990000"><span class="style1 style2">Search :</span></td>
          </tr>
          <tr>
            <td width="374" height="96" align="center" valign="middle" bgcolor="#990000"><span class="style1 style2">
              <label>
              <div align="left">Keyword :
                <input name="search" type="text" id="search" size="40" />
              </div>
              </label>
            </span>
            <td width="56" align="center" valign="middle" bgcolor="#990000">
              <div align="left">
                <input type = "submit" name="submit" value="search" />
            </div></td>
          </tr>
        </table>
      </form>
</body>
</html>



search.php

<html>
<title>Search</title>

</head>

<body><br /><br />
<div class="MySearch"></div><br />
<?php

//Get data


$button = $_GET['submit'];
$search = $_GET['search'];

if (!$button)
   echo "You didn't submit a keyword.";
else
{
   if (strlen($search)<=1)
      echo "Search term too short";
   else
   {
      echo "You searched for <b>$search</b><hr size='1'>";

      //connect to database
      mysql_connect("localhost","root","");
      mysql_select_db("idoc");

             
            //explode search term
            $search_exploded = explode(" ",$search);

            foreach($search_exploded as $search_each);
            {

                //Construct Query

                $x++;
                if ($x==1)
                   $construct .= "file_name LIKE '%$search_each%'";
                else
                   $construct .= " OR file_name LIKE '%$search_each%'";

            }

     
 
      //echo out construct

     $construct = "SELECT * FROM document WHERE $construct";
     $run = mysql_query($construct);

     $foundnum = mysql_num_rows($run);

     if ($foundnum==0)
        echo "No results found";
     else
     {
        echo "$foundnum results found!<p>";

        while ($runrows = mysql_fetch_assoc($run))
        {
         //Get data
         $ref = $runrows['file_ref'];
         $filename = $runrows['file_name'];
         $owner = $runrows['owner'];
         $url = $runrows['url'];
         echo "
        <table>	

<tr>

 <td> $ref </td>
 <td> $filename </td>
 <td> $owner </td>
 <td><a href='$url'>$url</a></td>

</tr> 
</table>
         ";
        }

     }


   }
}

?>