我的 PHP 代码有一个问题,说“注意:未定义的索引”我确信它非常简单,因为我是初学者,所以我不太了解到底出了什么问题,所以请帮助我。
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>
这是php代码
<?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";
}
}
?>