problem with SEARCH CODE
Posted: Wed Mar 04, 2009 4:07 am
hi all to my friends in PHP, well maybe this is my 2nd week working with websites and php, thats why im getting too much troubles as im not that good in it,,, today i have a problem with the search code,,, actually i downloaded the code from the internet, and i tried my best to modify it, but i cant get any useful result,,,
(
well guys, i would be thankful as usual if you could help me plss
with this
n here is the PHP
thanking you all n thanking this site for the great help they provide 
well guys, i would be thankful as usual if you could help me plss
with this
Code: Select all
h2>Search</h2>
<form name="search" method="post" action="search.php">
Seach for:
<input type="text" name="find" /> in
<Select NAME="field">
<option value="std_id" selected>Student ID</option>
<Option VALUE="std_f_nm">First Name</option><br>
<Option VALUE="std_l_nm">Last Name</option>
<Option VALUE="std_major">Student Major</option>
<Option VALUE="std_hp">Student H/P</option>
<Option VALUE="std_email">Email</option>
<Option VALUE="std_c_hour">CR Hour</option>
<Option VALUE="std_pass">Password</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>n here is the PHP
Code: Select all
<?
include ('access.php');
//This is only displayed if they have submitted the form
if ($searching =="yes")
{
echo "<h2>Results</h2><p>";
//If they did not enter a search term we give them an error
if ($find == "")
{
echo "<p>You forgot to enter a search term";
exit;
}
// Otherwise we connect to our Database
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("fypms") or die(mysql_error());
// We preform a bit of filtering
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);
//Now we search for our search term, in the field the user specified
$data = mysql_query("SELECT * FROM std WHERE upper($field) LIKE'%$find%'");
//And we display the results
while($result = mysql_fetch_array( $data ))
{
echo $result['std_id'];
echo " ";
echo $result['std_f_nm'];
echo "<br>";
echo $result['std_l_nm'];
echo "<br>";
echo $result['std_major'];
echo "<br>";
echo $result['std_hp'];
echo "<br>";
echo $result['std_email'];
echo "<br>";
echo $result['std_c_hour'];
echo "<br>";
echo $result['std_pass'];
echo "<br>";
echo "<br>";
}
//This counts the number or results - and if there wasn't any it gives them a little message explaining that
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}
//And we remind them what they searched for
echo "<b>Searched For:</b> " .$find;
}
?>