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.
This is my form
<form action="search.php" method="post">
Search by Name From Database:<br>
<input type="text" name="search" id="snacks"/><br>
<input type="submit" value="Search"/>
</form>
this is php code
<?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 ("<b>Search Not Found. .</b>");
}
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 "<fieldset><b>No Results Found for Search Query '$search_term'</b></fieldset>";
}
else
{
echo "<table border='0' font color='red' bgcolor='lightblue'>
<tr align='left' >
<th><font color='green'>ID</font></th>
<th><font color='green'>Name</font></th>
<th><font color='green'>Salary</font></th>
<th><font color='green'>Location</font></th>
<th><font color='green'>Contact</font></th>
<th><font color='green'>Occupation</font></th>
</tr>" ;
while ($row = mysql_fetch_array($result1)){
echo "<div align=center></div>";
"
<tr bgcolor='lightgrey'>
<td>$row[0]</td>
<td>$row[1]</td>
<td>$row[2]</td>
<td>$row[3]</td>
<td>$row[4]</td>
<td>$row[5]</td>
</tr>";
}
print "</table>\n";
}
}
?>