problem with SEARCH CODE

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
moonkalous86
Forum Newbie
Posts: 8
Joined: Tue Mar 03, 2009 10:59 am

problem with SEARCH CODE

Post by moonkalous86 »

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

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;
}
?>
thanking you all n thanking this site for the great help they provide :)
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: problem with SEARCH CODE

Post by requinix »

moonkalous86 wrote:today i have a problem with the search code
Are you going to explain what or do we need to guess?
moonkalous86
Forum Newbie
Posts: 8
Joined: Tue Mar 03, 2009 10:59 am

Re: problem with SEARCH CODE

Post by moonkalous86 »

tasairis wrote:
moonkalous86 wrote:today i have a problem with the search code
Are you going to explain what or do we need to guess?
sorry the code doesnt return any result,,
i tried to search for a data that i stored but i can get anything it gives me blank page...


sorrrry again
moonkalous86
Forum Newbie
Posts: 8
Joined: Tue Mar 03, 2009 10:59 am

Re: problem with SEARCH CODE

Post by moonkalous86 »

guys some1 to help me here plx
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: problem with SEARCH CODE

Post by requinix »

You probably have register_globals turned off.

Everytime you use a variable that's supposed to come from a form you need to use the $_GET or $_POST arrays.

Code: Select all

echo $searching;
// $searching isn't defined anywhere
 
$searching = $_POST["searching"];
echo $searching;
// now it works
moonkalous86
Forum Newbie
Posts: 8
Joined: Tue Mar 03, 2009 10:59 am

Re: problem with SEARCH CODE

Post by moonkalous86 »

tasairis wrote:You probably have register_globals turned off.

Everytime you use a variable that's supposed to come from a form you need to use the $_GET or $_POST arrays.

Code: Select all

echo $searching;
// $searching isn't defined anywhere
 
$searching = $_POST["searching"];
echo $searching;
// now it works

thanks for ur help



but i could get anything
the result is like this
yes
Results

You forgot to enter a search term
Post Reply