User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,701 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,166 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 4319 | Replies: 7
Reply
Join Date: Oct 2006
Posts: 7
Reputation: mmarif4u is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
mmarif4u mmarif4u is offline Offline
Newbie Poster

Help Filtering My sql through Php using drop down menu and text field

  #1  
Oct 4th, 2006
Hi every one,
I have a little problem in php.
problem is that i want to search mysql table by php coding.
In php i want to use Drop down menu And a text field.
I have mysql table name is guestbook, now i use two entries
in dropdown menu (By Id,By name).and in the search text area
i type the any name selecting by name fom dropdown menu and then click on search button. Then it gave me the result in table format.
i Want the code for php how to retrieve data and what is the coding
for html form (Dropdown menu,text box,search button).

Can any one help me
Thanks.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2006
Location: NYC
Posts: 133
Reputation: sn4rf3r is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
sn4rf3r's Avatar
sn4rf3r sn4rf3r is offline Offline
Junior Poster

Re: Filtering My sql through Php using drop down menu and text field

  #2  
Oct 4th, 2006
so write it, theres not much to it.

1. need a db connection and database structure
2. need a form
3. need to wite some sql
4. need to format the html

look around, you will probibly find some examples or tutorials out there.
Last edited by tgreer : Oct 6th, 2006 at 4:33 pm. Reason: Removed unnecessary quote block.
Reply With Quote  
Join Date: Oct 2006
Posts: 7
Reputation: mmarif4u is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
mmarif4u mmarif4u is offline Offline
Newbie Poster

Re: Filtering My sql through Php using drop down menu and text field

  #3  
Oct 4th, 2006
I try on that but i am not successful in php code can
u help in php coding.
Thanks
Last edited by mmarif4u : Oct 4th, 2006 at 10:29 pm.
Reply With Quote  
Join Date: Sep 2006
Location: NYC
Posts: 133
Reputation: sn4rf3r is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
sn4rf3r's Avatar
sn4rf3r sn4rf3r is offline Offline
Junior Poster

Re: Filtering My sql through Php using drop down menu and text field

  #4  
Oct 5th, 2006
If you have a specific question, yes I will help. If you want to hire a programmer then post in the jobs section.

Otherwise do your homework, and use google,yahoo,ask.com there are millions of sites out there that have tutorials and samples including this one.
Last edited by tgreer : Oct 6th, 2006 at 4:32 pm. Reason: Removed unnecessary quote block.
Reply With Quote  
Join Date: Oct 2006
Posts: 7
Reputation: mmarif4u is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
mmarif4u mmarif4u is offline Offline
Newbie Poster

Re: Filtering My sql through Php using drop down menu and text field

  #5  
Oct 5th, 2006
thanks for reply.
ok
I have html page coding:

[html]<h2>Search</h2>
<form name="search" method="post" action="Search.php">
Seach for: <input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="fname">First Name</option>
<Option VALUE="lname">Last Name</option>
<Option VALUE="info">Profile</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>[/html]

Now Php Which have to search the database & Print results.

[php]<?
if ($searching =="yes")
{
echo "<h2>Results</h2><p>";

if ($find == "")
{
echo "<p>You forgot to enter a search term";
exit;
}
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("db") or die(mysql_error());

$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);

$data = mysql_query("SELECT * FROM users WHERE upper($field) LIKE'%$find%'");

while($result = mysql_fetch_array( $data ))
{
echo $result['fname'];
echo " ";
echo $result['lname'];
echo "<br>";
echo $result['info'];
echo "<br>";
echo "<br>";
}

$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}

echo "<b>Searched For:</b> " .$find;
}
?>[/php]


The problem is that it cannot display the Results.
Whats wrong with this code.
Can u help me.
Thanks.
Last edited by tgreer : Oct 6th, 2006 at 11:36 am. Reason: Added code tags.
Reply With Quote  
Join Date: Sep 2006
Location: NYC
Posts: 133
Reputation: sn4rf3r is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
sn4rf3r's Avatar
sn4rf3r sn4rf3r is offline Offline
Junior Poster

Re: Filtering My sql through Php using drop down menu and text field

  #6  
Oct 6th, 2006
Are you getting an error or just no data returned?
try this
$sql = "SELECT * FROM users WHERE upper($field) LIKE'%".$find."%'"
die($sql);
$data = mysql_query($sql); 

Looks like you put the find variable inside of single quotes which treat it as literal. mysql is looking for $find and not the contents of that variable.
The die function will exit the script and echo out the query, if it looks good then comment out the die and continue.
Last edited by tgreer : Oct 6th, 2006 at 4:32 pm. Reason: Removed unnecessary quote block.
Reply With Quote  
Join Date: Oct 2006
Posts: 7
Reputation: mmarif4u is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
mmarif4u mmarif4u is offline Offline
Newbie Poster

Re: Filtering My sql through Php using drop down menu and text field

  #7  
Oct 6th, 2006
I just try ur code but it also doesnt return results.
I mean that the page is blank Nothing is displayed.
Reply With Quote  
Join Date: Sep 2006
Location: NYC
Posts: 133
Reputation: sn4rf3r is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
sn4rf3r's Avatar
sn4rf3r sn4rf3r is offline Offline
Junior Poster

Re: Filtering My sql through Php using drop down menu and text field

  #8  
Oct 9th, 2006
make sure you have errors turned on
<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
?>

It sounds like youre script is failing before it even gets to the die() function.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 2:45 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC