title: How to solve "Notice: Undefined index"?
body: <p>I have a problem with my PHP code saying that "Notice: Undefined index" I am sure its very simple, since I am a beginner i am not getting well what is wrong exactly so please help me.</p>
  
  <pre><code>This is my form
  
  &lt;form action="search.php" method="post"&gt;
  Search by Name From Database:&lt;br&gt;
  &lt;input type="text" name="search" id="snacks"/&gt;&lt;br&gt;
  &lt;input type="submit" value="Search"/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>this is php code</p>
  
  <pre><code>&lt;?php
   $search_term = $_POST["search"];
   mysql_connect("localhost", "root", "") or die("Could not connect: " . mysql_error());
   mysql_select_db("mydata");
  
  if(empty($search_term))
  {
      echo ("&lt;b&gt;Search Not Found. .&lt;/b&gt;");
  }
  else
  {
  $result1= mysql_query( "SELECT * FROM loc WHERE name LIKE '%$search_term%' " ) 
  or die("SELECT Error: ".mysql_error()); 
  
  $count= mysql_num_rows($result1);
  
  if ($count == 0)
  {
  echo "&lt;fieldset&gt;&lt;b&gt;No Results Found for Search Query '$search_term'&lt;/b&gt;&lt;/fieldset&gt;";
  }
  else
   {
   echo "&lt;table border='0' font color='red' bgcolor='lightblue'&gt;
   &lt;tr align='left' &gt;
   &lt;th&gt;&lt;font color='green'&gt;ID&lt;/font&gt;&lt;/th&gt;
   &lt;th&gt;&lt;font color='green'&gt;Name&lt;/font&gt;&lt;/th&gt;
   &lt;th&gt;&lt;font color='green'&gt;Salary&lt;/font&gt;&lt;/th&gt;
   &lt;th&gt;&lt;font color='green'&gt;Location&lt;/font&gt;&lt;/th&gt;
   &lt;th&gt;&lt;font color='green'&gt;Contact&lt;/font&gt;&lt;/th&gt;
   &lt;th&gt;&lt;font color='green'&gt;Occupation&lt;/font&gt;&lt;/th&gt;
   &lt;/tr&gt;" ;
   while ($row = mysql_fetch_array($result1)){ 
  
   echo "&lt;div align=center&gt;&lt;/div&gt;";
    "
     &lt;tr bgcolor='lightgrey'&gt;
     &lt;td&gt;$row[0]&lt;/td&gt;
       &lt;td&gt;$row[1]&lt;/td&gt;
      &lt;td&gt;$row[2]&lt;/td&gt;
      &lt;td&gt;$row[3]&lt;/td&gt;
      &lt;td&gt;$row[4]&lt;/td&gt;
      &lt;td&gt;$row[5]&lt;/td&gt;
      &lt;/tr&gt;";
  
  
      } 
  
     print "&lt;/table&gt;\n"; 
   }
   }
  
  ?&gt; 
  </code></pre>